wxPython - Panel Class


Advertisements

Widgets such as button, text box, etc. are placed on a panel window. wx.Panel class is usually put inside a wxFrame object. This class is also inherited from wxWindow class.

Although controls can be manually placed on panel by specifying the position in screen coordinates, it is recommended to use a suitable layout scheme, called sizer in wxPython, to have better control over the placement and address the resizing issue.

In wxPanel constructor, the parent parameter is the wx.Frame object in which the panel is to be placed. Default value of id parameter is wx.ID_ANY, whereas the default style parameter is wxTAB_TRAVERSAL.

wxPython API has the following sizers, using which controls are added into a panel object −

S.N. Sizers & Description
1

wx.BoxSizer

Widgets are arranged in a vertical or horizontal box

2

wx.StaticBoxSizer

Adds a staticbox around the sizer

3

wx.GridSizer

One control each added in equal sized cells of a grid

4

wx.FlexGridSizer

Control added in cell grid can occupy more than one cell

5

wx.GridBagSizer

Controls explicitly positioned in a grid and spanning over more than one row and/or column

Sizer object is applied as the layout manager of the panel using SetSizer() method of wxPanel class.

wx.Panel.SetSizer(wx.???Sizer())

Panel object in turn is added to the top level frame.

wxpython_major_classes.htm
Advertisements