Python 连接2个小部件,PyQt

Python 连接2个小部件,PyQt,python,pyqt4,qt-designer,Python,Pyqt4,Qt Designer,我在不破坏主循环的情况下连接两个窗口时遇到问题。你能帮我连接这两个PyQt文件吗?第二个文件应通过按下按钮打开 # usr/bin/env python # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui # from Monster import aknator try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromU

我在不破坏主循环的情况下连接两个窗口时遇到问题。你能帮我连接这两个PyQt文件吗?第二个文件应通过按下按钮打开

# usr/bin/env python

# -*- coding: utf-8 -*-



from PyQt4 import QtCore, QtGui
# from Monster import aknator

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig,_encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


def Aknator():
   from Monster import aknator







class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1695, 885)
        self.gridLayout = QtGui.QGridLayout(Form)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.commandLinkButton = QtGui.QCommandLinkButton(Form)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Segoe UI"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.commandLinkButton.setFont(font)
        self.commandLinkButton.setMouseTracking(False)
        self.commandLinkButton.setAccessibleDescription(_fromUtf8(""))
        self.commandLinkButton.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.commandLinkButton.setAutoFillBackground(False)

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.commandLinkButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Aknator)

        QtCore.QMetaObject.connectSlotsByName(Form)
        Form.setTabOrder(self.commandLinkButton, #Future comadndlinks)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Monster Hunter 4 Ultimate Pro", None))
        self.commandLinkButton.setText(_translate("Form", "Akantor", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
这是第二个文件:

# usr/bin/env python

# -*- coding: utf-8 -*-



from PyQt4 import QtCore, QtGui





try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s


try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1096, 399)
        Form.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.gridLayout = QtGui.QGridLayout(Form)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.verticalLayout_5 = QtGui.QVBoxLayout()
        self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
        self.label = QtGui.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(20)
        self.label.setFont(font)
        self.label.setObjectName(_fromUtf8("label"))
        self.verticalLayout_5.addWidget(self.label)
        self.textEdit = QtGui.QTextEdit(Form)
        self.textEdit.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.verticalLayout_5.addWidget(self.textEdit)
        self.gridLayout.addLayout(self.verticalLayout_5, 0, 1, 1, 1)
        self.verticalLayout_8 = QtGui.QVBoxLayout()
        self.verticalLayout_8.setObjectName(_fromUtf8("verticalLayout_8"))
        self.pushButton_5 = QtGui.QPushButton(Form)
        self.pushButton_5.setMaximumSize(QtCore.QSize(550, 200))
        font = QtGui.QFont()
        font.setPointSize(26)
        self.pushButton_5.setFont(font)
        self.pushButton_5.setAutoFillBackground(False)
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.verticalLayout_8.addWidget(self.pushButton_5)
        self.gridLayout.addLayout(self.verticalLayout_8, 2, 2, 1, 1)
        self.verticalLayout_7 = QtGui.QVBoxLayout()
        self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
        self.label_2 = QtGui.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(20)
        self.label_2.setFont(font)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.verticalLayout_7.addWidget(self.label_2)
        self.textEdit_2 = QtGui.QTextEdit(Form)
        self.textEdit_2.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
        self.verticalLayout_7.addWidget(self.textEdit_2)
        self.gridLayout.addLayout(self.verticalLayout_7, 0, 2, 1, 1)
        self.verticalLayout_6 = QtGui.QVBoxLayout()
        self.verticalLayout_6.setObjectName(_fromUtf8("verticalLayout_6"))
        self.gridLayout.addLayout(self.verticalLayout_6, 2, 1, 1, 1)

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.pushButton_5, QtCore.SIGNAL(_fromUtf8("clicked()")), drops)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Monster Hunter 4 Ultimate Pro", None))
        self.label.setText(_translate("Form", "Weapon Damage", None))
        self.textEdit.setHtml(_translate("Form", "Not Important HTML Code", None))

if __name__=="__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

假设您的文件名为
a.py
b.py
,将b导入到a中,在其上创建一个新的对象调用
show

a、 派克

b、 派克

我不得不注释掉你的一些代码以使其运行,所以在发布你的问题之前,确保你粘贴在Stackoverflow上的代码运行

我不会建议您继续这样做,您应该学会相应地构造项目,而不是修改qt设计器中自动生成的ui文件

请查看这些链接,以帮助您组织PyQt项目和

我的github repo是PySide,但概念仍然相同


如果这个答案已经解决了你的问题,请考虑通过点击复选标记来接受它。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。没有义务这样做。
# usr/bin/env python

# -*- coding: utf-8 -*-



from PyQt4 import QtCore, QtGui
from b import Ui_Form2

# from Monster import aknator

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig,_encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


def Aknator():
   from Monster import aknator



class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1695, 885)
        self.gridLayout = QtGui.QGridLayout(Form)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.commandLinkButton = QtGui.QCommandLinkButton(Form)
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Segoe UI"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.commandLinkButton.setFont(font)
        self.commandLinkButton.setMouseTracking(False)
        self.commandLinkButton.setAccessibleDescription(_fromUtf8(""))
        self.commandLinkButton.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.commandLinkButton.setAutoFillBackground(False)

        self.page2 = QtGui.QWidget()
        ui = Ui_Form2()
        ui.setupUi(self.page2)

        self.commandLinkButton.clicked.connect(self.page2.show)

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.commandLinkButton, QtCore.SIGNAL(_fromUtf8("clicked()")), Aknator)

        QtCore.QMetaObject.connectSlotsByName(Form)
        #Form.setTabOrder(self.commandLinkButton)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Monster Hunter 4 Ultimate Pro", None))
        self.commandLinkButton.setText(_translate("Form", "Akantor", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
# usr/bin/env python

# -*- coding: utf-8 -*-



from PyQt4 import QtCore, QtGui





try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s


try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form2(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1096, 399)
        Form.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.gridLayout = QtGui.QGridLayout(Form)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.verticalLayout_5 = QtGui.QVBoxLayout()
        self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
        self.label = QtGui.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(20)
        self.label.setFont(font)
        self.label.setObjectName(_fromUtf8("label"))
        self.verticalLayout_5.addWidget(self.label)
        self.textEdit = QtGui.QTextEdit(Form)
        self.textEdit.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.verticalLayout_5.addWidget(self.textEdit)
        self.gridLayout.addLayout(self.verticalLayout_5, 0, 1, 1, 1)
        self.verticalLayout_8 = QtGui.QVBoxLayout()
        self.verticalLayout_8.setObjectName(_fromUtf8("verticalLayout_8"))
        self.pushButton_5 = QtGui.QPushButton(Form)
        self.pushButton_5.setMaximumSize(QtCore.QSize(550, 200))
        font = QtGui.QFont()
        font.setPointSize(26)
        self.pushButton_5.setFont(font)
        self.pushButton_5.setAutoFillBackground(False)
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.verticalLayout_8.addWidget(self.pushButton_5)
        self.gridLayout.addLayout(self.verticalLayout_8, 2, 2, 1, 1)
        self.verticalLayout_7 = QtGui.QVBoxLayout()
        self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
        self.label_2 = QtGui.QLabel(Form)
        font = QtGui.QFont()
        font.setPointSize(20)
        self.label_2.setFont(font)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.verticalLayout_7.addWidget(self.label_2)
        self.textEdit_2 = QtGui.QTextEdit(Form)
        self.textEdit_2.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
        self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
        self.verticalLayout_7.addWidget(self.textEdit_2)
        self.gridLayout.addLayout(self.verticalLayout_7, 0, 2, 1, 1)
        self.verticalLayout_6 = QtGui.QVBoxLayout()
        self.verticalLayout_6.setObjectName(_fromUtf8("verticalLayout_6"))
        self.gridLayout.addLayout(self.verticalLayout_6, 2, 1, 1, 1)

        self.retranslateUi(Form)
        #QtCore.QObject.connect(self.pushButton_5, QtCore.SIGNAL(_fromUtf8("clicked()")), drops)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Monster Hunter 4 Ultimate Pro", None))
        self.label.setText(_translate("Form", "Weapon Damage", None))
        self.textEdit.setHtml(_translate("Form", "Not Important HTML Code", None))