Sizing in a Splitter Window?

Robin Dunn wrote:

Alex Zeiger wrote:

I have some static text objects in a splitter window's subwindow. Ideally, the objects should expand to cover the entire subwindow whenever the parent frame is resized. The text should be centered with each object occupying an equal amount of space.

splitter = wx.SplitterWindow(self,-1)
p1 = wx.Window(self.splitter, -1)
t1 = wx.StaticText(p1, -1, "text1", style=wx.ALIGN_CENTRE)
t1.SetBackgroundColour(wx.Colour(255, 0, 0))
t2 = wx.StaticText(p1, -1, "text2", style=wx.ALIGN_CENTRE)
t2.SetBackgroundColour(wx.Colour(0, 255, 0))
t3 = wx.StaticText(p1, -1, "text3", style=wx.ALIGN_CENTRE)
t3.SetBackgroundColour(wx.Colour(0, 0, 255))

box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(t1, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
box.Add(t2, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)
box.Add(t3, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5)

p1.SetAutoLayout(1)
p1.SetSizer(box)
box.Fit(p1)
box.SetSizeHints(p1)
p1.Layout()

Unfortunately, when the parent window is resized, the text objects retain their previous dimensions. Am I seting this up correctly? Any help is appreciated.

Contrary to what is implied in the docs, wx.Window does not do autolayout (because then non-container windows like wx.Button would support autolayout too and that just doesn't make sense!)

So you can give your wx.Window a EVT_SIZE handler that calls self.Layout(), or just switch it to a wx.Panel.

Yeah, switching to a Panel worked fine. Thanks a lot.