如何打开第二个窗口pyqt?

时间:2015-02-27 03:08:56

标签: python pyqt

打开第二个窗口时遇到问题。我有两个文件:

main.py

# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import sys
class Ui_Form(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.setupUi(self)
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(581, 415)
    self.pushButton_6 = QtGui.QPushButton(Form)
        self.pushButton_6.setGeometry(QtCore.QRect(485, 60, 91, 22))
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))
        self.pushButton_6.setText(_translate("Form", "О Приложении", None))
        self.pushButton_6.clicked.connect(self.about_us)
    def about_us(self):
        import info
        about = info.Ui_MainWindow()
        about.show()
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    ex = Ui_Form()
    ex.setWindowTitle('Шифровальщик')
    ex.show()
    sys.exit(app.exec_())

info.py

# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import sys
class Ui_MainWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.setupUi(self)
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(433, 289)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
        self.textBrowser.setGeometry(QtCore.QRect(0, 10, 431, 241))
        self.textBrowser.setObjectName(_fromUtf8("textBrowser"))
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(350, 250, 80, 22))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.pushButton.setText(_translate("MainWindow", "Ok", None))
        self.pushButton.clicked.connect(self.exit)
    def exit(self):
        sys.exit()
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    ex = Ui_MainWindow()
    ex.show()
    sys.exit(app.exec_())

怎么了?

1 个答案:

答案 0 :(得分:-1)

def about_us(self):
    import info
    about = info.Ui_MainWindow()
    about.show()

我在尝试调用window show时出错了

def about_us(self):
    import info
    self.about = info.Ui_MainWindow()
    self.about.show()