There seem to be a few ways to use the wx.Timer; Here's one.

   1 def on_timer(event):
   2     pass  # do whatever
   3 
   4 TIMER_ID = 100  # pick a number
   5 timer = wx.Timer(panel, TIMER_ID)  # message will be sent to the panel
   6 timer.Start(100)  # x100 milliseconds
   7 wx.EVT_TIMER(panel, TIMER_ID, on_timer)  # call the on_timer function

For some reason, this code didn't work when I tried it. The reason was the timer had to be a class member. If you put that code into the __init__() method and add self. before timer, it should work. If it doesn't, try making on_timer() a class member too. -- PabloAntonio

EVT_CLOSE & the Timer

I've had problems closing my frame, when there was a Timer running.

Here's how I handled it:

   1 def on_close(event):
   2     timer.Stop()
   3     frame.Destroy()
   4 
   5 wx.EVT_CLOSE(frame, on_close)

It seems that if you don't stop the timer, it won't actually quit.

See Also

Timer (last edited 2009-04-09 08:14:00 by 78-9-246-190)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.