Started learning wxPython so I could make an application. I’m having issues with nested sizers in particular.
class browser_mainPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.toolbar()
self.searchBar = wx.SearchCtrl(self)
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer2 = wx.BoxSizer(wx.VERTICAL)
main_sizer2.Add(self.toolBar, 0, wx.EXPAND, 5)
main_sizer2.Add(self.searchBar, 0, wx.EXPAND, 5)
main_sizer.Add(main_sizer2, wx.EXPAND)
tree_panel = wx.Panel(self)
tree_panel.SetBackgroundColour(wx.BLACK)
entry_panel = wx.Panel(self)
entry_panel.SetBackgroundColour(wx.GREEN)
main_sizer3 = wx.BoxSizer(wx.HORIZONTAL)
main_sizer3.Add(tree_panel, 0, wx.EXPAND, 5)
main_sizer3.Add(entry_panel, 0, wx.EXPAND, 5)
main_sizer2.Add(main_sizer3, wx.EXPAND)
self.SetSizer(main_sizer)
Right, so the problem is that the two panels in main_sizer3 aren’t expanding out as I want them to. Here’s a picture.
What I want is for the two panels to expand to the rest of the panel with the black portion
being smaller than the green panel width-wise. Can’t find a solution for the life of me.
I plan on making these two panels have their own special instances because there’s going to be stuff happening in them but for now, I’m looking to implement them as simply as possible before I start getting into the details.
You forgot a few proportions:
Furthermore, your
main_sizeronly contains one entry which makes it superfluous. Also try to give your sizers somewhat meaningful names to make it easier to read.Last but not least, if you want the user to be able to dynamically resize the proportions of the two panels (tree and entry), you
can use a
wx.SplitterWindow: