![](/img/trans.png)
[英]Tkinter function “root.after()” doesn't run the function specified
[英]Run function after t time
我有一個問題是:在t_total
某個時間后有一個可變的總時間是t_total
,我想運行一些函數,並且該時間繼續向上或向下計數到t_total
。 它看起來像: ---t1---t2--
當時間等於t1時運行一個函數,而在t2中時運行另一個函數。 我試圖做一個計數功能:
for t in range(t_total):
t = t + 1
time.sleep(1)
if t = t1:
function1()
但是如果遵循該功能,則在運行function1時,計時將停止。 那么,是否仍要保持計數繼續運行function2?
你可以使用線程
import threading
for t in range(t_total):
t = t + 1
time.sleep(1)
if t = t1:
threading.Thread(target=function1).start()
添加到功能1中以在時間t開始啟動一個新計時器。 您可以將t,t1和t2的值導出到函數1中並繼續使用新的計時器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.