[wxPython-users] Drawing panel backgrounds with widgets visible on top

Frank Aune Frank.Aune at broadpark.no
Wed Oct 17 07:02:26 PDT 2007


On Wednesday 17 October 2007 15:31:17 Andrea Gavana wrote:
> On 10/17/07, Andrea Gavana wrote:
> > I would try using wx.EVT_ERASE_BACKGROUND, something like this (self
> > is your panel):
> >
> > self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
> >
> > def OnErase(self, event):
> >
> >    dc = event.GetDC()
> >    if not dc:
> >        dc = wx.ClientDC(self)
> >
> >    panelSize = self.GetClientSize()
> >    bmpWidth, bmpHeight = self.theBitmap.GetWidth(),
> > self.theBitmap.GetHeight()
> >
> >    xPos = (panelSize.x - bmpWidth)/2
> >    yPos = (panelSize.y - bmpHeight)/2
> >
> >    dc.DrawBitmap(xPos, yPos, self.theBitmap)

Hello Andrea,

This actually worked almost perfect. Only problem is that the "old" background  
image is not updated when resizing the application. Insted the old position 
and the new position is meshed(?) together.

But when alt-tab'ing so the app window is hidden behind some other window and 
re-focused again, it will display as it should.

I guess this require some sort of Update() command, but haven't found the 
magic line yet :-)

-Frank




More information about the wxpython-users mailing list