[wxPython-users] boxsizers problem

Phil Mayes phil at philmayes.com
Sat Sep 9 17:12:52 PDT 2006


At 04:03 PM 9/9/2006, you wrote:
>Hi!
>
>I am running into a dead end while trying to combine several widgets
>containing their own sizers into sizers of higher-level widgets.
>
>Precisely: I have a topwidget, inherited from wx.Frame, which
>contains two subwidgets. One of these widgets is a wx.Window, the
>other one is a widget inherited from wx.Window, which intself contains two
>wx.Windows. The latter two wx.Windows are placed by a wx.BoxSizer, as
>well as the two medium-level widgets are within the toplevel widget.
>
>This doesn't work: the lowest-level widgets are stacked on top of each
>other. What is my mistake?
>Greetings!
>
>                Moritz
>
>The code looks like this (colors added in order to see the placement):
>
>
>import wx
>
>
>class MainWindow(wx.Frame):
>     def __init__(self):
>         wx.Frame.__init__(self, None,-1,"Trainer")
>         self.SetBackgroundColour(wx.CYAN)
>         self.Subwindow = Subwindow(self)
>         self.Nextsubwindow = wx.Window(self, -1, size=(100,100))
>         self.Nextsubwindow.SetBackgroundColour(wx.RED)
>         vertical_sizer = wx.BoxSizer(wx.VERTICAL)
>         vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
>         vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
>         self.SetSizer(vertical_sizer)
>         self.SetAutoLayout(1)
>         vertical_sizer.Fit(self)
>
>class Subwindow(wx.Window):
>     def __init__(self, mother_widget):
>         wx.Window.__init__(self, mother_widget,-1)
>         self.SetBackgroundColour(wx.BLACK)
>         self.FirstWidget = wx.Window(self,-1, size=(50,50))
>         self.FirstWidget.SetBackgroundColour(wx.BLUE)
>         self.SecondWidget = wx.Window(self,-1, size=(50,50))
>         self.FirstWidget.SetBackgroundColour(wx.GREEN)
>         horizontal_sizer = wx.BoxSizer(wx.HORIZONTAL)
>         horizontal_sizer.Add(self.FirstWidget, 1, wx.EXPAND)
>         horizontal_sizer.Add(self.SecondWidget, 1, wx.EXPAND)
>         self.SetSizer(horizontal_sizer)
>         self.SetAutoLayout(1)
>         horizontal_sizer.Fit(self)

Instead of adding the windows at
         vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
         vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
add the sizer that holds them instead.

Phil Mayes 






More information about the wxpython-users mailing list