wxpython Timer Event Interval

10,164

Solution 1

I wrote a tutorial on timers a while back that might help you figure this out. Basically you do as you mentioned in the first code snippet. You have to Start the timer and pass it a value in milliseconds. So 1000 would = 1 second. You don't need that bit with the wx.TimerEvent. At least, I've never needed that.

Anyway, the timer event fires every 750 milliseconds in your example, or a little less than a second. I think if you machine's CPU gets pegged, it can interrupt or delay timer events, but otherwise they're very reliable.

Solution 2

In addition, if you want to control how often the EVT_TIMER occurs, you must set up the second parameter, the boolean oneShot. By default, it is set to False, but you can specify something like self.timer.Start(milliseconds = 750, oneShot = True), and the timer will still shoting untill the self.timer.Stop() bit appears.

All the best.

Share:
10,164
Kevin
Author by

Kevin

Updated on June 04, 2022

Comments

  • Kevin
    Kevin almost 2 years

    I am trying to write a gui application with wx python and I need to control the interval of the timer event. Here is my code currently:

    self.timer = wx.Timer(self)
    self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)        
    self.timer.Start(750) # start timer after a delay
    

    This is the right framework but I cannot control the interval or how often the EVT_TIMER occurs. I have been trying to figure out using the wx TimerEvent class but without any luck. I feel like this should be what I need but it isn't working:

    self.timer = wx.Timer(self)
    self.timerEvent = wx.TimerEvent(self.timer.GetId(),10)
    self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) 
    

    Thanks!