Search code examples
python-3.xwxpythonpanel

Add left panel to bottom and top panel


The code I have makes a top and bottom pannel I need to add a left panel as seem in the picture below:

My current code is:

import wx

class MainFrame(wx.Frame):
    def __init__(self,parent):
        wx.Frame.__init__(self,parent,title="myapp",size=(800,580))
        self.split_win =wx.SplitterWindow(self)
        self.top = wx.Panel(self.split_win ,style = wx.SUNKEN_BORDER)
        self.bottom = wx.Panel(self.split_win ,style = wx.SUNKEN_BORDER)
        self.split_win.SplitHorizontally(self.top,self.bottom,450)
        st1 = wx.StaticText(self.bottom, -1, "This is an example of static text", (20, 10))
        self.bottom.SetBackgroundColour('white')


app = wx.App()
frame=MainFrame(None).Show()
app.MainLoop()

I need s left panel like the one in the picture where I can add a button and combobox.

enter image description here

I would also like to know if it is possible to have bottom and left and top panel without split?

Thanks for the help


Solution

  • Welcome to sizers in wx.python
    Start here: https://wxpython.org/Phoenix/docs/html/sizers_overview.html

    import wx
    
    class MainFrame(wx.Frame):
        def __init__(self,parent):
            wx.Frame.__init__(self,parent,title="myapp",size=(800,580))
            self.top = wx.Panel(self, style = wx.SUNKEN_BORDER)
            self.bottom = wx.Panel(self ,style = wx.SUNKEN_BORDER)
            self.left = wx.Panel(self ,style = wx.SUNKEN_BORDER, size = (150,-1))
            st1 = wx.StaticText(self.bottom, -1, "This is an example of static text")
            st2 = wx.StaticText(self.left, -1, "Left Panel", (20, 10))
            self.bottom.SetBackgroundColour('white')
    
            sizer1 = wx.BoxSizer(wx.VERTICAL)
            sizer1.Add(self.top,1,wx.EXPAND,5)
            sizer1.Add(self.bottom,1,wx.EXPAND,5)
    
            sizer2 = wx.BoxSizer(wx.HORIZONTAL)
            sizer2.Add(self.left,0,wx.EXPAND,5)
            sizer2.Add(sizer1,1,wx.EXPAND,5)
    
            self.SetSizer(sizer2)
    
    app = wx.App()
    frame=MainFrame(None).Show()
    app.MainLoop()
    

    enter image description here