Tkinter -- the best way to make a realtime loop

eb303 eric.brunel at
Thu Oct 8 09:30:12 CEST 2009

On Oct 8, 12:40 am, J Wolfe <vorticitywo... at> wrote:
> What's the best way to make a realtime loop in Tkinter?  I know in
> perl you can use "repeat" and it will call a function every x seconds,
> in python it seems like "after" may be the equivalent though it
> doesn't seem to behave like the perl repeat function. Any ideas?
> Thanks,
> Jonathan

Well, I don't know the Perl 'repeat' function, but AFAICT, after seems
to be the way to go in Tkinter. Maybe something like this:
from Tkinter import *

root = Tk()

var = IntVar()

def incr():
  var.set(1 + var.get())
  root.after(1000, incr)

Label(root, width=10, textvariable=var).pack()
Button(root, text='Go!', command=incr).pack()



More information about the Python-list mailing list