[Tutor] Timer

Kent Johnson kent37 at tds.net
Tue Dec 6 16:24:38 CET 2005


Joseph Quigley wrote:

> I'd like to make a 30 minute timer. How an I do that? With time?

A little context would be helpful. If you are writing a standalone app 
that just needs to wait 30 minutes, then do something, use time.sleep().

If the program needs to be able to do something else at the same time as 
the timer is running, you will have to put the sleep() call in a 
separate thread. threading.Timer will do this for you, see this recipe 
for an example of its use:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440476

If you are running in a GUI app, the GUI toolkit may have a timer you 
can use, for example in Tkinter widgets have an after() method that 
schedules a callback for a future time; wxPython has wx.FutureCall.
http://www.pythonware.com/library/tkinter/introduction/x9507-alarm-handlers-and-other.htm
http://www.wxpython.org/docs/api/wx.FutureCall-class.html

Kent





More information about the Tutor mailing list