[英]Way to repeatedly execute a function without extra modules every x seconds?
是的,我很新,我一直在尋找答案,但我似乎找不到適合自己的答案。
這個問題和我的差不多,但是我需要每隔一個執行一個函數。比如說1.2秒,而不會中斷或阻塞整個while循環。
我不使用模塊(時間除外)的原因是因為對我來說唯一可用的模塊是: Builtins , math , matplotlib.pyplot , numpy , operator , processing , pygal , random , re , string , time , turtle和urllib .request 。
有這種方法嗎?
如果有可用的turtle,則可以將tkinter作為turtle.TK使用。 然后,您可以使用root.after(1200, function. args)
function(*args)
每1.2秒執行一次function(*args)
。 在[tkinter] root.after
搜索SO將給出許多有用的示例問題。 但是,一旦這樣做,就必須使所有事情都由事件驅動,並且事件處理程序不要花很長時間來阻塞事件循環。
編輯:烏龜包裝tkinter.after
作為turtle.ontimer(function, milleseconds)
。 該函數不能接受參數。 如果這是某種“家庭作業”問題,則可能是預期的解決方案。 有一個例子在這里 。
使用模塊時間。 您已將其列入清單。
import time
def function():
print(1)
while True:
time.sleep(1.2)
function()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.