I was trying to build a simple stopwatch app using py-gtk. Here is the callback function for the toggle button in my stopwatch window.
def start(self,widget):
if widget.get_active():
widget.set_label('Stop')
else:
self.entry.set_text(str(time.time() - s))
widget.set_label('Start')
It works perfectly well except for the fact that time does not get continuously get displayed in the entry widget. If I add an infinite while loop inside the ‘If ‘ condition like ,
while 1:
self.entry.set_text(str(time.time() - s))
the window becomes unresponsive. Can someone help?
Use gobject.timeout_add:
to have gtk call
self.update()every 500 milliseconds.In the
updatemethod check if the stopwatch is active and callas necessary.
Here is fairly short example which draws a progress bar using
gobject.timeout_add: