imagewxpythonboxsizer

WxPython StaticLine after Image in BoxSizer


I am trying to put a StaticLine(Vertical) after an Image. After the static line, I have some buttons. I have put all of them in a BoxSizer(Horizontal). But while running I do not see the static line. What am I doing wrong here? Please help me.

Thanks.

Here is some code.

class Frame1(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        self.panel1 = wx.Panel(self, wx.ID_ANY)
        img = wx.EmptyImage(MaxImageSize, MaxImageSize)
        self.imgctrl = wx.StaticBitmap(self.panel1, wx.ID_ANY, wx.BitmapFromImage(img))
        self.st = wx.StaticLine(self.panel1, wx.ID_ANY, style=wx.LI_VERTICAL)
        self.but = wx.Button(self.panel1, wx.ID_ANY, 'OK')
        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.hbox.Add(self.imgctrl, 0, wx.ALL, 5)
        self.hbox.Add(self.st, 0, wx.ALL, 5)
        self.hbox.Add(self.but, 1, wx.ALL, 5)
        self.panel1.SetSizer(self.hbox)
        self.hbox.Fit(self.panel1)

Solution

  • When you add the staticline to the sizer you need to set the expand flag, so it expands to fill the sizer vertically.

    import wx
    
    class Frame1(wx.Frame):
        def __init__(self, *args, **kwds):
            wx.Frame.__init__(self, *args, **kwds)
            self.panel1 = wx.Panel(self, wx.ID_ANY)
            img = wx.EmptyImage(100, 100)
            self.imgctrl = wx.StaticBitmap(self.panel1, wx.ID_ANY, wx.BitmapFromImage(img))
            self.st = wx.StaticLine(self.panel1, wx.ID_ANY, style=wx.LI_VERTICAL)
            self.but = wx.Button(self.panel1, wx.ID_ANY, 'OK')
            self.hbox = wx.BoxSizer(wx.HORIZONTAL)
            self.hbox.Add(self.imgctrl, 0, wx.ALL, 5)
            self.hbox.Add(self.st, 0, wx.ALL | wx.EXPAND, 5)
            self.hbox.Add(self.but, 1, wx.ALL, 5)
            self.panel1.SetSizer(self.hbox)
            self.hbox.Fit(self.panel1)
    
    if __name__ == '__main__':
        app = wx.App(False)
        frame_1 = Frame1(None)
        frame_1.Show()
        app.MainLoop()