I'd like to put TreeCtrl on both side of SplitterWindow. And, of course, TreeCtrl should be expanded as window's size.
splitter = wx.SplitterWindow(self, style = wx.SP_BORDER)
leftPanel = wx.Panel(splitter)
rightPanel = wx.Panel(splitter)
leftSizer = wx.BoxSizer(wx.VERTICAL)
rightSizer = wx.BoxSizer(wx.VERTICAL)
localTree = wx.TreeCtrl(leftPanel)
flickrTree = wx.TreeCtrl(rightPanel)
leftSizer.Add(localTree, flag = wx.EXPAND | wx.ALIGN_CENTER)
rightSizer.Add(flickrTree, flag = wx.EXPAND)
splitter.SplitVertically(leftPanel, rightPanel)
leftPanel.SetSizer(leftSizer)
leftPanel.SetAutoLayout(1)
leftSizer.Fit(leftPanel)
I've tried above code, but TreeCtrl's height is not expanded as I expected.
What's wrong with it?
asked Aug 19, 2011 at 7:42
Hongseok Yoon
3,3488 gold badges39 silver badges53 bronze badges
1 Answer 1
The following works for me:
splitter = wx.SplitterWindow(self, style = wx.SP_BORDER)
leftPanel = wx.Panel(splitter)
rightPanel = wx.Panel(splitter)
localTree = wx.TreeCtrl(leftPanel)
leftSizer = wx.BoxSizer(wx.VERTICAL)
leftSizer.Add(localTree, 1, wx.EXPAND | wx.ALL)
leftPanel.SetSizer(leftSizer)
flickrTree = wx.TreeCtrl(rightPanel)
rightSizer = wx.BoxSizer(wx.VERTICAL)
rightSizer.Add(flickrTree, 1, wx.EXPAND | wx.ALL)
rightPanel.SetSizer(rightSizer)
splitter.SplitVertically(leftPanel, rightPanel)
The key thing is to set the proportion value when adding the TreeCtrl to the BoxSizer, i.e:
leftSizer.Add(localTree, 1, wx.EXPAND | wx.ALIGN_CENTER)
rather than:
leftSizer.Add(localTree, flag = wx.EXPAND | wx.ALIGN_CENTER)
Otherwise, it defaults to zero.
Sign up to request clarification or add additional context in comments.
Comments
lang-py