我想在使用tkinter的GUI時異步地調用一個函數。我試圖運行一個打印命令,該命令將異步運行到GUI,而不會凍結並每0.5秒重複一次。我不明白如何從我看過的教程中做到這一點,並希望得到一些幫助。這裏以濃縮代碼爲例來說明我遇到的問題。我也使用python 2.7以防萬一。python 2.7與tkinter的異步函數
import Tkinter as tk
class TestClass(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.create_view()
def create_view(self):
self.labelTitle = tk.Label(self, text="Live Camera Page",)
self.labelTitle.pack()
def asynchronous_function(self):
print("I would like this to repeat every 0.5 seconds ...")
app = TestClass()
app.geometry("800x600")
app.mainloop()
看看Tkinter的''後''方法。 – jasonharper
您是否嘗試過創建單獨的線程? –
我已經嘗試創建一個單獨的線程,但我無法得到它在tkinter內工作。這是我真正遇到的問題。 – ConorYoungs