将变量传递给子表单PYQT5

时间:2017-03-10 23:59:19

标签: python python-3.x pyqt pyqt5

我试图将一个数字传递给子形式,但是当我调用该变量时,它并没有给我传递给它的内容。而不是得到一个数字我得到"< main .MyApp对象在0x03232E40>"我的号码被分配给"父母"变量。我做错了什么?

此声明正在启动子表单:

self.child_win = childForm(self, 123) 

这部分是接收传递的变量:

def __init__(self,  myInt, parent=None):

以下是完整的代码:

import sys
from PyQt5 import uic, QtWidgets

qtCreatorFile = "parent_form.ui" 
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
LandingPageUI, LandingPageBase = uic.loadUiType("child_form.ui")

class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)

        self.btnOpenChild.clicked.connect(self.showChildForm) 


    def showChildForm(self):
        self.child_win = childForm(self, 123)        
        self.child_win.show()      


class childForm(LandingPageBase, LandingPageUI):
    def __init__(self,  myInt, parent=None):
        QtWidgets.QMainWindow.__init__(self)
        LandingPageBase.__init__(self)
        self.setupUi(self)

        self.myInt = myInt

        print("My int: " + str(self.myInt))


if __name__ == "__main__":
    app=QtWidgets.QApplication.instance() 
    if not app:  
         app = QtWidgets.QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())

0 个答案:

没有答案