wxpython Timer Event Interval

ε祈祈猫儿з 提交于 2019-12-23 12:02:12

问题


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!


回答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.




回答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.



来源:https://stackoverflow.com/questions/10486500/wxpython-timer-event-interval

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!