2013-04-16 27 views
1

我有一個程序,它將檢查幾個條件並檢查數據是否可用。如果有任何缺失的數據,我會彈出另一個窗口,將收集該窗口中的數據。它將有兩個按鈕(應用和關閉)。我想在觸發按鈕後返回一個值。如何等待在python的其他窗口執行

program.pydataEntry.py都有自己的用PyQt Disigner設計的UI。

我想讓我的程序等待其他窗口的返回值。並根據輸入我會繼續我的其他過程。

比方說,程序文件是program.py和另一個窗口dataEntry.pyprogram.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 
+0

你應該已經爲數據入口和程序提供了gui pys,以便我們可以在給你一個答案之前進行測試。 – scottydelta

回答

0

首先進口的DataEntry的.py在program.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得到一個值。