我是 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 …Run Code Online (Sandbox Code Playgroud)