Timing in MacPython?

Fredrik Lundh fredrik at pythonware.com
Wed Dec 15 09:40:15 EST 1999


ventrego at yahoo.com wrote:
> I'm trying to create a simple timer application - something like a 
> kitchen timer, just computerized.  However, I'm running into several 
> problems:
> 
> First,can I force TKinter update the window?  I've set up a label and a 
> button with TKinter textvariables, but the changes don't happen until 
> after my program returns to idle - in this case, after the time interval 
> has elapsed.  I'd like to have changes updated while the timer's waiting,
> so that the user knows everything's working correctly.

    widget.update_idletasks()

(but in this case, using "after" is a much better
idea.  see below).

> Second, is there an easy way to sound the system alert sound?   I'm 
> referring the one that people can choose in the Sound/Monitors & Sound 
> control panel.  It's possible to create a waveform and play it a la' the 
> morse.py demo program, but this seems excessively inelegant.

    widget.bell()

> Finally, is there a non-blocking time-delay command?  I'm using 
> time.sleep(1), which is working well, but it stops all other processes 
> from executing.  Ideally, I'd like this timer to run in the background!
> If I was on a UNIX system, I'd use signals, which would be VERY easy,
> but I'm a Mac addict at heart. :)

    widget.after(time, callback)

see:
http://www.pythonware.com/library/tkinter/introduction/basic-widget-methods.htm
=> "event processing" and "alarm handlers" for more info.

</F>





More information about the Python-list mailing list