From: WinCrazy Date: Sat, 17 Jul 2010 09:59:49 -0700 (PDT) Local: Sat, Jul 17 2010 12:59 pm Subject: Re: Using OnTimer and OnPaint together Kevin, You won't find this anywhere in the docs: Avoiding redraw flicker may a big problem, but it's very platform-dependent. It has to do with the underlying OS's particular graphics refresh system. With MS Windows using a wx.PaintDC may cause a very annoying "flash" or "flicker" on each redraw. I've had success using a wx.ClientDC instead to draw at any time at all instead of a wx.PaintDC (only) on OnPaint events. Other platforms get flicker if a wx.PaintDC is NOT used ! I've read that using a wx.ClientDC or a wx.BufferedDC( wx.ClientDC() ) might be the ticket there. Always use a sub-class of wx.DC and not a wx.DC, itself. There are (too) many subclassed DC's and almost no useful guidelines about which one will work best for you. So, start by using a wx.PaintDC and if you get redraw flicker try a wx.ClientDC. Keep experimenting until it works right. Ray ----------------------------------------------------------------------------------------------- From Robin Dunn: You can easily get the same, or even worse, flicker using a ClientDC. It is not a magic bullet. Flicker on MSW typically comes from two things. 1) Clearing the window before drawing, and 2) allowing partially completed drawing steps to be visible on the screen before the whole set of drawing operations is completed. Number 1) can be eliminated by catching EVT_ERASE_BACKGROUND and doing nothing in the handler. This prevents the default handler from being called which will clear the widget. You should also be able to accomplish the same thing by calling theWindow.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) although it's not clear if that works on all platforms in 2.8. BTW, if you are not going to be drawing the entire contents of the window in your EVT_PAINT then you probably do not want to prevent the background from being cleared and you will need to deal with this differently. Number 2) can be solved by using a double buffered drawing technique. Essentially you do all your drawing steps into a bitmap the same size as the window and then when you are all done you draw that bitmap to the screen. That way there are no partially completed drawing steps that are visible to the user, there is just one step that they can see and that is the completed drawing. There are a couple different approaches that can be used for double buffering. A) The first is to (re)create the bitmap each time you need to update the screen and draw the whole content to it each time and the throw it away when you are done with that paint event. B) The other is to keep the bitmap around and only update the parts of it that have changed. There are also some DC classes which derive from wx.MemoryDC that help you to do double buffered drawing: wx.BufferedDC and wx.BufferedPaintDC. There are some examples in the demo and the wiki. -- Robin Dunn Software Craftsman http://wxPython.org