我想把TreeCtrl放在SplitterWindow的两边。当然,TreeCtrl应该扩展作为窗口的大小。
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)
我已经尝试了上面的代码,但是TreeCtrl的高度并没有像我预期的那样扩展。
它出了什么问题?
答案 0 :(得分:1)
以下适用于我:
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)
关键是在将TreeCtrl添加到BoxSizer时设置比例值,即:
leftSizer.Add(localTree,1,wx.EXPAND | wx.ALIGN_CENTER)
而不是:
leftSizer.Add(localTree,flag = wx.EXPAND | wx.ALIGN_CENTER)
否则,默认为零。