Is there a built-in method in python (preferably within Tkinter) that runs a function or manipulates a variable for a set duration?
I want to simulate a blinking of a circle..
Thank you!
Is there a built-in method in python (preferably within Tkinter) that runs a function or manipulates a variable for a set duration?
I want to simulate a blinking of a circle..
Thank you!
Tkinter's Tk has a background (scheduled) function caller: Tk.after. It basically calls your function (f) after (m) milliseconds: Tk.after(m, f). So if you wanted to make your circle blink, you could do:
# Mock setup
class Circle:
def __init__(self):
self.on = True
def toggle(self):
self.on = not self.on # Switches from `True` to `False` or `False` to `True`
def draw(...):
...
...
circle = Circle()
root = tkinter.Tk()
def external_toggle_call():
circle.toggle()
circle.draw(...) # Again, pseudo
root.after(100, external_toggle_call) # Recurse after 100 milliseconds
external_toggle_call()
root.mainloop()