Timer

Peter Otten __peter__ at web.de
Wed Mar 17 05:16:17 EDT 2010


Sam Bull wrote:

> I'm writing a pyGTK program, and I need to display the contents of a
> window for a few seconds before automatically moving on. I have tried
> using the time.sleep method, but this has problems, such as the program
> becoming unresponsive.
> 
> I have now attempted to use a timer, but this does not seem to run the
> function at the end of the time. The code of my latest attempt:
> 
> def next(self=None, testnum=10, testspeed=5):
>     self.count += 1
>     #Sets label, telling the user the next word to memorise
>     self.nobtns.set_markup("Word %s is: %s" % (self.count,
> self.words[self.count-1]))
>     self.nobtns.show()
>     if self.count == testnum: #When all words are shown
>         self.nobtns.hide()
>     else:
>         self.timer = threading.Timer(testspeed, self.next, [testnum,
> testspeed])
>         self.timer.start()
> 
> Putting a print statement at the beginning of the function, I can see
> that the function is not being run by the timer. Any help on getting
> this working would be appreciated.

GUI toolkits usually have their own way of handling timeouts. I don't know 
pygtk, but the following looks promising:

http://www.pygtk.org/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html

Peter



More information about the Python-list mailing list