我使用2個框架(A和B),我可以在兩個框架之間進行切換,以使程序運行。 此前tkinter框架等待難題
while Conditions:
self.frameA.wait_window()
後來,當我完成了frameA:
self.frameA.destroy()
self.frameB = FrameB(self)
self.frameB.wait_window()
#After I'm finished with B...
#Function that takes info from frames A and B to make the program run
self.frameB.destroy()
self.frameA = FrameA(self)
和交替來回程序的時間。但我開始認爲銷燬和重新初始化可以做得更好。現在我使用grid_forget()爲像第二個init那樣工作的框架創建了一個函數。我現在的問題是,因爲我沒有破壞幀,所以wait_window從不中斷,造成無限循環。我玩弄了合併2幀的想法,但這並不能解決我的wait_window問題。從本質上講,有沒有辦法讓我的應用程序等待來自幀的輸入,還是回到原始方法的最佳解決方案?
while firstConditions():
while secondConditions():
self.play()
#Other code after secondConditions is false
def play(self):
w = messagebox.askyesno(message='Make changes?', parent=self)
if w:
#Deals with making changes
self.frameA.wait_window()
然後在frameA一個按鈕將導致frameB創建
def makeFrameB(self):
self.frameA.grid_forget()
self.frameB.newInit()
self.frameB.grid(row=3, column=0, columnspan=3)
self.frameB.wait_window()
我使用wait_window的理由是,如果我不這樣做,我會得到與消息框出現在一個無限循環並結束。
'wait_window'不是用來像你使用它一樣 - 它幾乎只用於等待模態對話框。你爲什麼認爲你需要調用'wait_window'?你能否給我們展示一個完整的工作示例,說明你在幾行代碼中要做什麼? –