[wxPython-users] Sizers / Panel

Mark Erbaugh mark at microenh.com
Tue Feb 5 21:56:48 PST 2008


On Tue, 2008-02-05 at 14:54 -0800, Robin Dunn wrote:
> Mark Erbaugh wrote:
> > I think I needs some help in understanding sizers (or someone to tell me
> > that my thinking is correct).
> > 
> > I create a frame that has a panel taking up the entire client area.  The
> > contents of the panel are managed by sizers.  After laying out the
> > contents, I do:
> > 
> > panel.SetSizer(sizer)
> > 
> > However, I find that I need to add another sizer to "link" the panel
> > sizers to the frame and to get the form to adjust to the size of the
> > panel.
> > 
> > sizer1 = wx.BoxSizer(wx.Sizer)
> > sizer1.Add(panel)
> > frame.SetSizer(sizer1)
> > frame.Fit()
> > 
> > Is this the correct approach?
> 
> Almost, (other than the bug on the first line.) If you want the panel to 
> fill the space given to the sizer (all of the frame's client area in 
> this case) then you should use
> 
> 	sizer1.Add(panel, 1, wx.EXPAND)
> 
> 
> Another approach that would also work is to just manually set the size 
> of the frame based on the needs of the panel as reported by its sizer, 
> something like this:
> 
> 	...
> 	panel.SetSizer(sizer)
> 	...
> 	frame.SetClientSize(sizer.CalcMin())
> 
> or even this:
> 
> 	sizer.Fit(frame)
> 

Robin,

Thanks.





More information about the wxpython-users mailing list