我正在尝试在wx.Notebook页面上创建一个wx.CollapsiblePane,该页面使用下面的最小代码示例成功完成。但是,展开窗格时,框架无法调整大小。但是,如果不是创建一个Notebook而是创建一个简单的Panel(请参阅代码中的注释行),框架会按预期调整大小。任何想法为什么它不适用于笔记本电脑?
编辑:我有机会在Windows上测试它并且它可以工作(wx 3.0.0.0和2.8)。 Linux中似乎只有一个问题(Ubuntu 13.10 with wx 2.8.12.1)。import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.panel = wx.Panel(self)
# Notebook setup
self.nb = wx.Notebook(self.panel)
#self.nb = wx.Panel(self.panel) # uncomment this for a working example
self.pagepanel = wx.Panel(self.nb)
self.nb.AddPage(self.pagepanel, 'page')
# add something to the Notebook page
checkbox = wx.CheckBox(self.pagepanel, -1, 'box 1')
# add CollapsiblePane to the Notebook page
colpane = wx.CollapsiblePane(self.pagepanel)
colpane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged)
# add something to the CollapsiblePane
win = colpane.GetPane()
checkbox2 = wx.CheckBox(win, -1, 'box 2')
# Set CollapsiblePane sizer
colpanesizer = wx.BoxSizer(wx.VERTICAL)
colpanesizer.Add(checkbox2, -1)
win.SetSizer(colpanesizer)
colpanesizer.SetSizeHints(win)
colpane.Collapse()
# set Notebook page sizer
pagesizer = wx.BoxSizer(wx.VERTICAL)
pagesizer.Add(checkbox)
pagesizer.Add(colpane)
self.pagepanel.SetSizerAndFit(pagesizer)
# set the whole Panel sizer
panelsizer = wx.BoxSizer()
panelsizer.Add(self.nb)
self.panel.Layout()
self.panel.SetSizerAndFit(panelsizer)
# set Frame size
self.Fit()
def OnPaneChanged(self, event):
# redo the layout
self.pagepanel.Layout()
self.pagepanel.Fit()
self.panel.Layout()
self.panel.Fit()
self.Fit()
app = wx.App()
frame = MyFrame()
frame.Center()
frame.Show()
app.MainLoop()
答案 0 :(得分:0)
colpanesizer.Add(checkbox2, -1)
应为colpanesizer.Add(checkbox2)
尝试:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.panel = wx.Panel(self)
# Notebook setup
self.nb = wx.Notebook(self.panel)
#self.nb = wx.Panel(self.panel) # uncomment this for a working example
self.pagepanel = wx.Panel(self.nb)
self.nb.AddPage(self.pagepanel, 'page')
# add something to the Notebook page
checkbox = wx.CheckBox(self.pagepanel, -1, 'box 1')
# add CollapsiblePane to the Notebook page
colpane = wx.CollapsiblePane(self.pagepanel)
colpane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged)
# add something to the CollapsiblePane
win = colpane.GetPane()
checkbox2 = wx.CheckBox(win, -1, 'box 2')
# Set CollapsiblePane sizer
colpanesizer = wx.BoxSizer(wx.VERTICAL)
colpanesizer.Add(checkbox2)
win.SetSizer(colpanesizer)
colpanesizer.SetSizeHints(win)
colpane.Collapse()
# set Notebook page sizer
pagesizer = wx.BoxSizer(wx.VERTICAL)
pagesizer.Add(checkbox)
pagesizer.Add(colpane)
self.pagepanel.SetSizerAndFit(pagesizer)
# set the whole Panel sizer
panelsizer = wx.BoxSizer()
panelsizer.Add(self.nb)
self.panel.Layout()
self.panel.SetSizerAndFit(panelsizer)
# set Frame size
self.Fit()
def OnPaneChanged(self, event):
# redo the layout
self.pagepanel.Layout()
self.pagepanel.Fit()
self.panel.Layout()
self.panel.Fit()
self.Fit()
app = wx.App()
frame = MyFrame()
frame.Center()
frame.Show()
app.MainLoop()