Tkinter -- the best way to make a realtime loop

eb303 eric.brunel at pragmadev.com
Thu Oct 8 03:30:12 EDT 2009


On Oct 8, 12:40 am, J Wolfe <vorticitywo... at gmail.com> 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()

root.mainloop()
---

HTH



More information about the Python-list mailing list