Home > Net >  root.after() in tkinter stops after first iteration?
root.after() in tkinter stops after first iteration?

Time:12-11

consider the following code.

from tkinter import *
root = Tk()
def do_something():
     print("hello")
     
     
     
root.after(100,do_something())
          
root.mainloop()

instead of calling the function do_something() every 100 milliseconds it stops after the first iteration

Is my understanding of root.after() wrong or am I making a mistake?

Any help will be appreciated.

CodePudding user response:

You're only executing the function once. To make it repeat, you should put root.after(100, do_something) in the function:

from tkinter import *
root = Tk()

def do_something():
    print("hello")
    root.after(100, do_something) # use do_something instead of do_something()
     
do_something()
          
root.mainloop()
  • Related