1

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

两者program.py都有dataEntry.py自己的用 PyQt Disigner 设计的 UI。

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

假设程序文件是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
4

1 回答 1

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 中获取值

于 2013-04-16T18:53:49.850 回答