如何在python中等待其他窗口中的执行

时间:2013-04-16 06:27:49

标签: python pyqt4 return-value

我有一个程序会检查几个条件并检查数据是否可用。如果有任何丢失的数据,那么我将弹出另一个窗口,该窗口将收集该窗口中的数据。它将有两个按钮(应用和关闭)。我想在触发按钮后返回一个值。

program.pydataEntry.py都有自己在PyQt Disigner中设计的用户界面。

我希望我的程序等待来自其他窗口的返回值。根据输入,我将继续我的其他过程。

假设程序文件为program.py,另一个窗口dataEntry.py导入program.py

我的dataEntry.py看起来像

#imports necessary modules 

class dataEntry(QtGui.QMainWindow,Ui_DataEntry):

    def __init__(self):

        super(dataEntry,self).__init__()
        self.setupUi(self)

        self.Btn_Apply.clicked.connect(self.ApplyChanges)
        self.Btn_Close.clicked.connect(self.CancelChanges)

    def ApplyChanges(self):
        #This will trigger when ApplyButonn is clicked
        #I want to return True value from here
        return True

    def CancelChanges(self):
        #This will trigger when CancelButonn is clicked
        #I want to return False value from here
        return False

我的program.py看起来像

from dataEntry import dataEntry

class MainApp(QtGui.QMainWindow,Ui_MainApp):

    def __init__(self):

        super(MainApp,self).__init__()
        self.setupUi(self)

        self.CheckDetails()

    def CheckDetails(self):
        #Here i will check if required data is present else i will take data from dataEntry class

        if checkFails:

            input = dataEntry()
            input.show()

            #Here i want this class to wait until i get the result from dataEntry class
            EntryResult = return value from dataEntry

            if EntryResult:
                #Do some thing when its True    
             else:
                #Do some thing when its False

1 个答案:

答案 0 :(得分:0)

首先在program.py中导入dataentry.py, 在你的program.py

之后
EntryResult = dataentry.py.Ui_DataEntry() #considering that the UI class in dataentry.py is Ui_DataEntry

这将运行dataentry.py并使dataentry.py返回所需的值。这样,program.py将一直等到从dataentry.py获取值