我正在开发一个监视计算机温度的python tkinter程序,我希望它在固定时间后更新温度值。 以下函数是我用来做的:
def update():
get_temp()#the function that get the computer temperature value, like cpu temperature.
...
def upd():
update()
time.sleep(0.3)
upd()#recursive call function.
upd()
但是这种方式会达到递归极限,所以程序会在一段时间后停止。
我想让它不断更新值,我该怎么办?
我不知道将其更改为 after()
是否会更好。
但是如果我使用 after()
,tkinter 窗口会卡住一段时间,所以我不想使用它。
谢谢。
最佳答案
它需要循环。 应该是:
def update():
get_temp()#the function that get the computer temperature value, like cpu temperature.
...
def upd():
while True:#needs a while true here and don't call upd() in this function.
update()
time.sleep(0.3)
upd()#this upd() is outside the function upd(),it used to start the function.
感谢所有帮助过我的人。
关于Python 递归限制以及如何持续监控某些内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71246549/