[Tutor] how to run a timer in window using TKINTER

Alan Gauld alan.gauld at btinternet.com
Thu Jan 10 10:34:19 CET 2008


"brindly sujith" <brindly at gmail.com> wrote

>i want to run a timer in a window
> 
> plz guide me how to do this

There is a timer facility in Tkinter for this.

In your window constructor add a call to self.after()
Add a callback function/lambda that closes the window.

> send me the Tkinter code for this
##############
from Tkinter import *

tk = Tk()
L =Label(tk, text="Wait for it!")
L.pack()
L.after(5000, tk.quit  )  # quit after 5000ms

tk.mainloop()
###############
Is the shortest I could think of...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list