I am writing a GUI that has a wx.Notebook control. One of the notebook tabs
needs to create another wx.Notebook. On the panel with the nested notebook
control, I am having problems arranging a wx.StaticBox so that it is flush with
the bottom of the panel.
I have supplied a minimal example of my problem. On Tab 2, the staticbox is not
flush with the bottom of the panel, and this is causing a minor aesthetic
problems for me. If I change the proportion argument from 0 to 1 when I add the
staticbox sizer to the box sizer (I have commented where to do this), then I can
indeed get the staticbox flush with the bottom of the panel. However, this
creates some vertical spacing below Button 2 that is inside of the staticbox.
What do I need to do to make the staticbox sit at the bottom of the panel
without adding any extra spacing around the button?
I am running Fedora 7 Linux with wxPython 2.8.8.1
···
###################################################################
#!/usr/bin/env python
import wx
from wx.lib.stattext import GenStaticText
class MyApp(wx.App):
def OnInit(self):
self.frame = Frame(None)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
class Frame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
notebook = wx.Notebook(self, id=wx.ID_ANY)
notebook.AddPage(TabOnePanel(notebook), "Tab 1")
notebook.AddPage(TabTwoPanel(notebook), "Tab 2")
sizer = wx.BoxSizer()
sizer.Add(notebook, 1, wx.ALL|wx.GROW)
self.SetSizerAndFit(sizer)
self.Layout()
class TabOnePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
button = wx.Button(self, wx.ID_ANY, "This is Button 1")
staticbox = wx.StaticBox(self, wx.ID_ANY, "StaticBoxOne")
staticBoxSizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
staticBoxSizer.Add((0, 20), 0)
staticBoxSizer.Add(button, 0, wx.GROW|wx.ALL)
vBoxSizer = wx.BoxSizer(wx.VERTICAL)
vBoxSizer.Add(staticBoxSizer, 0, wx.GROW|wx.ALL)
self.SetSizerAndFit(vBoxSizer)
self.Layout()
class TabTwoPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
nestedNotebook = wx.Notebook(self, wx.ID_ANY)
nestedNotebook.AddPage(MyNestedNotebookPanel(nestedNotebook),
"Nested Tab")
vBoxSizer = wx.BoxSizer(wx.VERTICAL)
vBoxSizer.Add(nestedNotebook, 1, wx.GROW)
self.SetSizerAndFit(vBoxSizer)
self.Layout()
class MyNestedNotebookPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
button = wx.Button(self, wx.ID_ANY, "This is Button 2")
staticbox = wx.StaticBox(self, wx.ID_ANY, "StaticBoxTwo")
staticBoxSizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
staticBoxSizer.Add(button, 0)
vBoxSizer = wx.BoxSizer(wx.VERTICAL)
vBoxSizer.Add((0, 50), 0)
#If I change the proportion argument below to "1", then
#the staticbox gets moved to the bottom of the panel, but
#it creates an odd space below the button
vBoxSizer.Add(staticBoxSizer, 0, wx.GROW|wx.ALL)
self.SetSizerAndFit(vBoxSizer)
if __name__ == "__main__":
app = MyApp()
app.MainLoop()