0

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!

user3431429
  • 101
  • 1
  • 7
  • 1
    possible duplicate of [Tkinter, executing functions over time](http://stackoverflow.com/questions/9342757/tkinter-executing-functions-over-time) – Steven Rumbalski Apr 16 '14 at 00:36

1 Answers1

0

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()
noahbkim
  • 528
  • 2
  • 13