I am starting using wx for my Python application and I run in a small problem when trying to include an image in a Frame.
I compiled this into a simple example. What I dont understand is that I have no problem of layout when replacing my image by text. Whe I try entering the image, the layout gets ruined.
Here is my layout with text, that contains only two elements. The logo, and the title of the application
And here is what I got when trying to insert the logo :
For some reason, the layout is ruined, and the title is placed on top left corner (and we can't see it anymore.)
Here is my code :
#!/usr/bin/env python import wx class IvolutionWindow(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(200, 100)) self.panel = wx.Panel(self) # Creating the title layout title = self.setup_titlelayout() # Creating the main grid maingrid = self.setup_maingrid(title) self.panel.SetSizer(maingrid) self.panel.Layout() self.Show(True) def setup_titlelayout(self): hbox = wx.BoxSizer(wx.HORIZONTAL) # used to contain logo part and text part vbox = wx.BoxSizer(wx.VERTICAL) # used to separate title and one-liner logobox = wx.BoxSizer(wx.HORIZONTAL) wx_logo = wx.EmptyBitmap(1, 1) # Create a bitmap container object. wx_logo.LoadFile("ivolution/data/media/vitruve_50.jpg", wx.BITMAP_TYPE_ANY) # Load it with a file image. #logo = wx.StaticBitmap(self, 1, wx_logo) logo = wx.StaticText(self.panel, label="Logo Here") # Change for proper logo title = wx.StaticText(self.panel, label="Ivolution") logobox.Add(logo) vbox.Add(title, flag=wx.RIGHT, border=8) hbox.Add(logobox, flag=wx.RIGHT, border=8) hbox.Add(vbox, flag=wx.RIGHT, border=8) return hbox def setup_maingrid(self, title): maingrid = wx.FlexGridSizer(4, 1, vgap=0, hgap=0) maingrid.Add(title) return maingrid def on_exit(self, event): self.Close(True) # Close the frame. if __name__ == "__main__": app = wx.App(False) frame = IvolutionWindow(None, "Ivolution") app.MainLoop() # Runs application
It should run on any computer if you change the location of the image to a correct one.
The only line of code changing between the two pictures is here :
#logo = wx.StaticBitmap(self, 1, wx_logo) logo = wx.StaticText(self.panel, label="Logo Here") # Change for proper logo
I am new with wxPython, so I guess there is something obvious here, but I can't find what.