Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

root.after() in tkinter stops after first iteration?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help will be appreciated.

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading