Python Forum

Full Version: StaticBitmap: unexpected behaviour
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everybody,

I am having a little issue with wx.StaticBitmap. I made a program using WxPython where i have several gadgets. At some point, i need to
have a wx.StaticBitmap next to a wx.StaticText, following the code

self.box_output = wx.BoxSizer(wx.HORIZONTAL)
self.text = wx.StaticText(self.panel, style=wx.TE_READONLY|wx.BORDER_SUNKEN | wx.TE_MULTILINE)
self.text.SetBackgroundColour((255,255,255))
self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage("myImg.png"))
self.box_output.Add(self.text,1,wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL,5)
self.box_output.Add(self.imageCtrl,2,wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL,1)

Later in the code i add this sizer to another one and i set this last one as the main sizer.

So far so good, when i run the program it is all fine, all widgets are showed properly. I can see the image in the right position.
The problem shows up when i try to update the bitmpap with a new image. Following the code:

def readPattern(self, value):
     #i do other stuff here without touching the bitmap
     bmp = wx.BitmapFromImage("img.png")
     self.imageCtrl.SetBitmap(bmp)
The previous method is called from another method. When the method is called, the bitmap updates with the correct image but the position is
wrong, i can actually see the same image twice and overlapping. By resizing the window manually, evertything goes as expected and the image is in the rigth position..

Any suggestions?

Thanks