wxpython 定时器事件间隔

编程入门 行业动态 更新时间:2024-10-10 09:22:10
本文介绍了wxpython 定时器事件间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试用 wx python 编写一个 gui 应用程序,我需要控制计时器事件的间隔.这是我目前的代码:

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

这是正确的框架,但我无法控制间隔或 EVT_TIMER 发生的频率.我一直在尝试使用 wx TimerEvent 类,但没有任何运气.我觉得这应该是我需要的,但它不起作用:

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)

谢谢!

推荐答案

我写了一个 定时器教程 可能会帮助您解决这个问题.基本上你按照你在第一个代码片段中提到的那样做.您必须启动计时器并向其传递一个以毫秒为单位的值.所以 1000 = 1 秒.wx.TimerEvent 不需要那个位.至少,我从来不需要那个.

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.

无论如何,在您的示例中,计时器事件每 750 毫秒或不到一秒触发一次.我认为如果您机器的 CPU 被锁定,它可以中断或延迟计时器事件,但否则它们非常可靠.

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.

更多推荐

wxpython 定时器事件间隔

本文发布于:2023-06-03 09:48:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/471185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定时器   间隔   事件   wxpython

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!