use*_*947 1 python pyqt exec qt-designer pyuic
我是 PyQt 的新手,所以当我创建 UI 文件时,我只是复制了一个 Mainwindow (mainfile.ui) 并将其更改为生成另一个 UI 文件 (Intro.ui)。我知道这不是创建 UI 文件的好方法,因为它总是给出错误:object has no attribute 'exec_'.
这是代码:
MainFile = "mainfile.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(MainFile)
FileIntro = "Intro.ui"
Ui_WindowIntro,_ = uic.loadUiType(FileIntro)
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.ButtonIntro.clicked.connect(self.OpenWindowIntro)
def OpenWindowIntro(self):
s = WindowIntro()
s.show()
s.exec_() #here is the problem.
class WindowIntro(QtWidgets.QMainWindow, Ui_WindowIntro):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_WindowIntro.__init__(self)
self.setupUi(self)
#close the window
self.Button2.clicked.connect(self.Close)
def Close(self):
self.close()
if __name__ == "__main__":
app = 0 # if not the core will die
app = QtWidgets.QApplication(sys.argv)
if login():
window = MainWindow()
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题。一旦 python 控制台显示这个AttributeError,内核就会死。
这个很好用,谢谢你的帮助:
from PyQt5 import QtGui, QtCore, QtWidgets
MainFile = "mainfile.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(MainFile)
FileIntro = "Intro.ui"
Ui_WindowIntro,_ = uic.loadUiType(FileIntro)
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.ButtonIntro.clicked.connect(self.OpenWindowIntro)
def OpenWindowIntro(self):
self.anotherwindow = WindowIntro()
self.anotherwindow.show()
class WindowIntro(QtWidgets.QMainWindow, Ui_WindowIntro):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_WindowIntro.__init__(self)
self.setupUi(self)
#close the window
self.Button2.clicked.connect(self.Close)
def Close(self):
self.close()
if __name__ == "__main__":
app = 0 # if not the core will die
app = QtWidgets.QApplication(sys.argv)
if login():
window = MainWindow()
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6290 次 |
| 最近记录: |