0
votes

I am working on a python tkinter program that monitoring computer temperature, and I want it to update the temperature value after a fixed time. the following function is what I used to do that:

    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()

but this way will hit the recursive limit, so the program will stops after a period of time. I want it to keep updating the value, what should I do? I don't know if I change it to after() it will be better or not. but if I use after(), the tkinter window will freeze a while, so I don't want to use it. Thank you.

1
Use a loop instead of recursion!Klaus D.
Don't recurse, use a loop. And I don't know how tkinter works, but most GUI frameworks have a timer function that will send a message after the timer expires so you don't have to block your main event loop while waiting for it.Mark Ransom

1 Answers

0
votes

You can run the update loop in another thread. Maybe try something like this:

import threading

def update():
    get_temp()
    time.sleep(0.3)

updateThread = threading.Thread(target=update)
updateThread.start()