Window Sizing Overview¶It can sometimes be confusing to keep track of the various size-related attributes of a wx.Window, how they relate to each other, and how they interact with sizers.
This document will attempt to clear the fog a little, and give some simple explanations of things.
âBest Sizeâ: the best size of a widget depends on what kind of widget it
is, and usually also on the contents of the widget. For example a
wx.ListBox âs best size will be calculated based on how many items it
has, up to a certain limit, or a wx.Button âs best size will be
calculated based on its label size, but normally wonât be smaller than the
platform default button size (unless a style flag overrides that). There is
a special method in the wxPython window classes called
wx.Window.DoGetBestSize that a class needs to override if it wants
to calculate its own best size based on its content.
âMinimal Sizeâ: the minimal size of a widget is a size that is
normally explicitly set by the programmer either
with the wx.Window.SetMinSize method or with
the wx.Window.SetSizeHints method. Most controls will also set
the minimal size to the size given in the controlâs constructor if a
non-default value is passed. Top-level windows
such as wx.Frame will not allow the user to resize the frame
below the minimal size.
âMaximum Sizeâ: just like for the minimal size, the maximum size is
normally explicitly set by the programmer with the
wx.Window.SetMaxSize method or with wx.Window.SetSizeHints.
Top-level windows such as wx.Frame will not allow the user to resize
the frame above the maximum size.
âSizeâ: the size of a widget can be explicitly set or fetched with the
wx.Window.SetSize or wx.Window.GetSize methods. This size
value is the size that the widget is currently using on screen and is the
way to change the size of something that is not being managed by a sizer.
âClient Sizeâ: the client size represents the widgetâs area inside of
any borders belonging to the widget and is the area that can be drawn upon
in a wx.EVT_PAINT event. If a widget doesnât have a border then its
client size is the same as its size.
âInitial Sizeâ: the initial size of a widget is the size given to the
constructor of the widget, if any. As mentioned above most controls will
also set this size value as the controlâs minimal size. If the size passed
to the constructor is the default wx.DefaultSize, or if the size is not
fully specified (such as wx.Size(150, -1)) then most controls will fill in
the missing size components using the best size and will set the initial
size of the control to the resulting size.
âVirtual Sizeâ: the virtual size is the size of the potentially viewable area of the widget. The virtual size of a widget may be larger than its actual size and in this case scrollbars will appear to the let the user âexploreâ the full contents of the widget. See wx.Scrolled for more info.