2013-03-20 284 views
1

我有一个循环,使用PySide根据用户输入的号码创建窗口 每个窗口都会有一些其他功能的调用。
我想在第一个窗口的所有命令完成后打开第二个窗口。
那么,有没有在Python的方式来告诉循环停止,直到一定的标志是TRUE例如在Python中暂停循环

下面是我在做什么

for i in range(values): 
    self.CreatWindow()  # the function that creates the window 



def CreatWindow(self): 
    window = QtGui.QMainWindow(self) 
    window.setAttribute(QtCore.Qt.WA_DeleteOnClose) 
    combo = QtGui.QComboBox(window) 
    combo.addItem(" ") 
    combo.addItem("60") 
    combo.addItem("45") 
    combo.activated[str].connect(self.onActivated) 

    btn = QtGui.QPushButton('OK', window) 
    btn.clicked.connect(self.ComputeVec) 
    window.show() 

def onActivated(self, text): 
    angle = int(text) 

def ComputeVec(self): 
    window.close() 
    getVecValue(angle) 

现在该功能的窗口有几个电话到其他函数,我想在最后一个函数getVecValue中将标志设置为True,它将执行一些计算并存储结果。

回答

2

而不是有一个不同的循环来打开新的窗口,你可以调用ComputeVec中的CreatWindow 并使用全局变量计数来维护之前创建的窗口数。

count = 0 
def ComputeVec(self): 
    window.close() 
    getVecValue(angle) 
    global count 
    count += 1 
    if count in range(values) : 
     self.CreatWindow() 
+0

工作感谢 – Lily 2013-03-24 12:27:12

0

由于函数调用self.CreateWindow等待被调用函数的返回值,所以循环的行为已经像这样。

您可以从self.CreateWindow例如return True返回一个适当的值,并做到这一点:

for i in range(values): 
    success = self.CreateWindow() 
    if success: 
     continue 

无论如何,如果在self.CreateWindow没有返回值,声明self.CreateWindow()仍在评估,结果None。直到达到这个结果,循环才结束。

+0

它不工作,如此下去,并创建另一个窗口 – Lily 2013-03-20 08:54:15

+0

所以我增加一些打印语句,以测试它是否工作 我加的是后'成功= self.CreateWindow print语句()'和当运行脚本时,它会创建所有窗口并在完成第一个窗口的工作前打印 – Lily 2013-03-20 10:28:08

+0

我编辑了主要问题 – Lily 2013-03-20 12:11:00