wxPython StaticText 小部件“闪烁”
我正在尝试制作一个数字时钟。它的问题之一是显示屏会“闪烁”。换句话说,wx.StaticText 小部件(在本例中为 self.ST)将在很短的时间内变为空白。我相信原因可能在于 self.ST 的更新方式(即 SetLabel())。有没有办法提供更平滑的过渡,以阻止闪烁?
这是更新 self.ST 的函数:
def tick (self):
''' Continually updates the time. '''
TimeStr = '%I:%M %S %p'
DateStr = '%A, %B %d, %Y'
Time = time.strftime(TimeStr)
Date = time.strftime(DateStr)
self.TimeDate = Time + '\t\t' + Date
self.ST.SetLabel(Time)
wx.CallLater(1000, self.tick)
I'm trying to make a digital clock. One of the problems with it is that the display will "flicker". In other words the wx.StaticText widget (self.ST in this case), will go blank for very short periods. I believe the cause may find it's root in how self.ST updates (ie, SetLabel()). Is there a way to provide smoother transitions, in an effort to stop the flickering?
This is the function where self.ST is updated:
def tick (self):
''' Continually updates the time. '''
TimeStr = '%I:%M %S %p'
DateStr = '%A, %B %d, %Y'
Time = time.strftime(TimeStr)
Date = time.strftime(DateStr)
self.TimeDate = Time + '\t\t' + Date
self.ST.SetLabel(Time)
wx.CallLater(1000, self.tick)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
修复闪烁的一种方法是在小部件的顶部容器中启用双缓冲。通常,这是通过在初始化程序中调用
self.SetDoubleBuffered(True)
来完成的,例如在StaticText
类的Panel
容器中。One way to fix the flickering is to enable double buffering in the top container for your widget. Normally this is done by calling
self.SetDoubleBuffered(True)
within the initialiser, for example withinPanel
container for yourStaticText
class.所发生的情况是,需要多次显示器刷新才能更新文本,或者它发生在与 hsync。
事实上,
StaticText
不会为您提供处理此问题所需的低级控制。你可以做的是使用
BufferedDC
和DrawText
,或者看看LEDNumberCtrl
。What happens is that it takes more than one monitor refresh to update the text or it happens in just the inappropriate time in regards to the hsync.
As it is,
StaticText
does not give you the low level control necessary to deal with this.What you can do is use a
BufferedDC
andDrawText
, or maybe take a look atLEDNumberCtrl
.我想你可以使用 wx.Timer 代替
请检查 wxpython 演示和 wx.Timer-class
I think you may use wx.Timer instead
Please check wxpython demo and wx.Timer-class