Python 递归限制以及如何持续监控某些内容

标签 python tkinter recursion

我正在开发一个监视计算机温度的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/

相关文章:

c++ - 需要有关反转输入的递归程序的帮助

python - 从 Python 中查找系统硬盘驱动器?

python - 用 python 解决一个 3x3 Frog 谜题

python - 查找 json 键以在 python 中打印不带括号的内容

Python Pygments 颜色错误

c++ - 在 std::function 中调用递归函数

java - Java中的数独求解器,使用回溯和递归

python - 将数组的 Python 字典转换为数据框

perl - 限制滚动条长度

python - Matplotlib tkagg 后端性能