[Tutor] Simple Tkinter question (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Oct 7 09:54:19 CEST 2005

> Danny, I got it:
> from Tkinter import *
> from time import *
> def my_update():
>    for i in range(3):
>      tv.set("Now it's %d"%i)
>      root.update()
>      sleep(1)
> root=Tk()
> tv=StringVar()
> Entry(textvariable=tv).pack()
> tv.set("Initial Value of StringVar")
> Button(text="Update", command=my_update).pack()
> root.mainloop()
> Trick is call to update() - which I found by looking at a few pages
> before the one your URL pointed me to, so THANKS!!! again.

Hi Mike,

Ok, that works too.  Another variation on your approach is the
update_idletasks() method, which like update() should handle all the
graphic-updating commands that are queued up for the GUI.  There's a
little more in:


that talks about what kind of GUI tasks are considered "idle", and when
you might want to call update() or update_idletasks().

The issue with update() is that while the program is sleeping, GUI
interaction, like button presses, will be ineffective, since we're still
not relinquishing control back to the GUI.

This may or may not be a problem for you.  You've probably seen programs
in the real world whose GUIs lag and drag when they do a lot of work.  If
that kind of program behavior annoys you, then you'll probably want to
search for another solution in your own programs.  *grin*

More information about the Tutor mailing list