2 problems:
1. The static text should not be a child of the frame, but of the panel.
2. Massive sizer confusion. You're adding the panel to the frame's sizer, and then also adding the staticbox to the same sizer even though they are not children of the same window. And then you are assigning the staticboxsizer to the staticbox. In other words, you are incorrectly crossing all kinds of hierarchy boundaries. There are a couple simple rules for sizers that will help you avoid these kinds of mistakes:
a. A sizer assigned to a window should only manage the children of that window, or subsizers that are managing other children of that window.
b. StaticBox and StaticBoxSizers don't appear to follow the rules, but they really do.
Compare yours with this:
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
sizer = wx.BoxSizer()
self.panel = wx.Panel(self)
sizer.Add(self.panel, 1, wx.EXPAND)
psizer = wx.BoxSizer(wx.VERTICAL)
self.panel.SetSizer(psizer)
box = wx.StaticBox(self.panel, -1, "Label Text Here")
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
t = wx.StaticText(self.panel, -1, "Some other text here")
bsizer.Add(t, proportion=1, flag=wx.ALL, border=10)
psizer.Add(bsizer, 1, wx.EXPAND|wx.ALL, 10)
self.SetSizer(sizer)
self.Fit()
app = wx.App(False)
frm = TestFrame()
frm.Show()
app.MainLoop()
···
On 2/9/10 11:20 AM, Patrick Tisdale wrote:
Hi,
I'm working on my first wxPython project, so be kind:-). I hacked up
the code snippet below from the StaticBox portion of the demo. I'm
having trouble getting the static text (t) to display properly. If I
set it's parent to self.panel, it displays on top of the StaticBox
label. If I set it's parent to self, it doesn't display at all. What
am I missing?
Thanks,
Patrick
---------------------------------------------------------------------------------------------------
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
sizer = wx.GridBagSizer(hgap=5, vgap=5)
self.panel = wx.Panel(self)
sizer.Add(self.panel, pos=(0,0), flag=wx.EXPAND)
box = wx.StaticBox(self.panel, -1, "Label Text Here")
sizer.Add(box, pos=(0,0))
bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
box.SetSizer(bsizer)
t = wx.StaticText(self, -1, "Some other text here")
bsizer.Add(t, proportion=1, flag=wx.ALL, border=10)
bsizer.Fit(box)
self.SetSizer(sizer)
self.Fit()
--
Robin Dunn
Software Craftsman