wxPython: Fit() works on wxPanel, but not on surrounding wxFrame
simo
simoninusa2001 at yahoo.co.uk
Thu May 20 13:34:47 EDT 2004
pit.grinja at gmx.de (Piet) wrote:
[snip]
> class myDialog(wxFrame):
> def __init__(self,parent,title):
> wxFrame.__init__(self,parent,-1, title, style=wxDEFAULT_FRAME_STYLE)
> self.panel = wxPanel(self,-1)
>
> The position of the controls on the wxPanel inside the frame is
> controlled by sizers, which are initialized as follows:
>
> self.MasterSizer=wxBoxSizer(wxVERTICAL)
> self.panel.SetSizer(self.MasterSizer)
> self.panel.SetAutoLayout(True)
> self.MasterSizer.Fit(self.panel)
> self.panel.Fit()
> self.Fit()
>
> To ensure that the size of the window and its layout always take into
> account the number of the controls, every function that will change
> the number of controls ends with the following threelines:
>
> self.MasterSizer.RecalcSizes()
> self.panel.Fit()
> self.Fit()
I don't think Fit() is needed, it's implied by:
self.MasterSizer.SetSizeHints(self)
But you've not used that. You've also not added the panel to the
sizer:
self.MasterSizer.Add(self.panel, 1, wx.ALL|wx.EXPAND, 0)
Also, I think you need a self.Layout() at the end of those three
lines.
Finally, beware of scrollbars, they're not at all well handled by wx's
sizers.
To get past the initial layout differing from the resized layout, I
usually would call your EVT_SIZE handler to do the initial layout too,
then you can just fix one function....
It's a bit hard to debug with only a snippet of code.
More information about the Python-list
mailing list