简体   繁体   中英

wxPython StaticText widget “flickering”

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)

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 within Panel container for your StaticText class.

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 and DrawText , or maybe take a look at LEDNumberCtrl .

我认为您可以改用wx.Timer,请检查wxpython演示和wx.Timer类

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM