我是由qt设计师制作的几个gui,想通过按钮连接它们
如果我在主gui中按下按钮,我想打开第二个gui
SecDialog是我的第二个gui,MainWindow是主要的gui
有什么问题?
import sys
from PyQt4 import QtCore, QtGui
from mainwindow import Ui_MainWindow
from secdialog import Ui_SecDialog
class SecDialog(QtGui.QDialog, Ui_SecDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.handleMainWindow)
def handleMainWindow(self):
window = SecDialog(self)
window.show
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())
答案 0 :(得分:0)
您需要在window.show
之后添加左括号和右括号:
import sys
from PyQt4 import QtCore, QtGui
from mainwindow import Ui_MainWindow
from secdialog import Ui_SecDialog
class SecDialog(QtGui.QDialog, Ui_SecDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.handleMainWindow)
def handleMainWindow(self):
window = SecDialog(self)
window.show() # <-- show is a method, therefore you need parentheses after it to call it
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())