[wxPython-users] Sizers / Panel

Robin Dunn robin at alldunn.com
Tue Feb 5 14:54:38 PST 2008


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 Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list