我目前正在創建一個將Tkinter輸入框插入Google Calendar的小程序(在所有不同類型的課程檢查之後)。這部分不是問題。 由於我在Tkinter窗口打開期間不想「保持」的同時運行終端。Python - 爲什麼我的Tkinter窗口沒有關閉self.destroy?
當我關閉使用
def quit(self):
self.thread.stop()
self.destroy()
窗口的所有部分消失的窗口,但窗口停留在屏幕上。
class window(Frame):
def __init__(self, parent, thread):
Frame.__init__(self, parent)
self.parent = parent
self.w = 600
self.h = 400
self.initUI()
self.center()
self.thread = thread
我用這個功能可按創建類:
def main(thread):
root = Tk()
root.resizable(width=False, height=False)
app = window(root, thread)
root.mainloop()
的MyThread的類。
class myThread(threading.Thread):
def __init__(self,threadType):
threading.Thread.__init__(self)
self.threadType = threadType
self.event = threading.Event()
def stop(self):
self.event.set()
def run(self):
if self.threadType == "new_app":
newappoint.main(self)
elif self.threadType == "main":
main()
有人可以告訴我,如果我錯過了一些東西,會使窗戶關閉正常。 線程關閉後調用self.quit()
tkinter和線程不好混,看例如http://stackoverflow.com/questions/10556479/running-a-tkinter-form-in-a-separate-thread –
@shivsn這工作,謝謝你: ) –
@JJHakala所以基本上,最好只使用我原來的主函數,然後讓'if __name__ == __main __:'循環尋找一個變量來更改並啓動Tkinter? –