0

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

1 Answer 1

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.

answered Aug 19, 2011 at 8:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.