Tkinter -- the best way to make a realtime loop

eb303 eric.brunel at pragmadev.com
Fri Oct 9 04:29:42 EDT 2009


On Oct 8, 7:15 pm, J Wolfe <vorticitywo... at gmail.com> wrote:
> Thank you both for your replies.  I had something similar to this:
>
> def incr():
>   var.set(1 + var.get())
>   root.after(1000, incr)
>
> except I had an extra set of parenthesis...
> def incr():
>   var.set(1 + var.get())
>   root.after(1000, incr())
>
> on the function which was screwing it up. Also needed to have a
> root.update() to refresh the GUI.

Mmmmm, no? The root.update() should not be necessary: the triggering
of the action specified in after(...) is done by the tk mainloop when
it's idle, and if it's idle, it means that it already has updated the
display. So no update() should be needed. What happens if you remove
it?



More information about the Python-list mailing list