I would like to have a window running and a process that runs in the background every 15 seconds. So far, I've learned that the tkinter after
method is a good way to do this, however I'm having trouble spacing the function calls out every 15 seconds. Here's an example of my current calling of after
:
import tkinter as tk
class Dummy():
def __init__(self):
self.top = tk.Tk()
self.open_flag = True
# set up the window layout, etc
def dummy_function(self):
print("Updating...")
def show(self):
while self.open_flag:
self.top.update_idletasks()
self.top.update()
self.top.after(15000, self.dummy_function)
I found that the above script would create the window, wait 15 seconds, and then execute a whole slew of calls to the dummy_function
in rapid sequence. After further research, I think this is because after
just schedules the provided function to get called after the provided delay and then it moves on without blocking. This would seem to cause the exact scenario that I talked about above.
I've tried calling time.sleep()
after the last line there (inside the while loop) in order to space out the calls of after
, but this gives me the colorful pinwheel of death on macOS and makes the entire window non-functional. Any ideas on how to space out these dummy_function
calls?