wxPython Panel class

wxPython Panel class

The Widgets which is shown in the frame of GUI window such as text box, buttons, static text etc. are put inside the panel class of the wxpython module. The panel class of wxpython module is usually put inside the frame class. The panel class of wxpython module is inherited from the wxWindow class present in wxpython module.

We can even place controls manually into the panel class present in our Python program by specifying the positions according to the coordinates of the screen where GUI window is being displayed.

But it is recommended to use a suitable layout scheme for the panel class that is called sizer in wxpython. This 'sizer' is used to have a better control over the resizing and placement issue that we will face while dealing with the panel class.

Inside the wxPanel constructor, the parameters which we will set for GUI window is placed with wxframe object. The object is used according to the where panel is to be placed in the GUI window.

Following are the default values for parameters present inside the panel class of wxpython module.

  • Default value for the ID parameter: The default value that we will use for the ID parameter in the panel class is 'wx.ID_ANY'.
  • Default value for the Style parameter: The default value that we will use for the Style parameter in the panel class is 'wxTAB_TRAVERSAL'.

In the panel class of wxpython module we have the following sizers that are used to add the controls in the GUI window:

  • wx.GridSizer: This sizer is used to control the each added controls in the panel class of wxpython module. It will set the each added control in equal sized cell in the form of a grid.
  • wx.FlexGridSizer: This sizer is used to control the each added controls in the panel class of wxpython module. It will add more the one of the each added control in a single grid.
  • wx.BoxSizer: This sizer is used to control the each added controls in the panel class of wxpython module. It will arrange the each added control in equal sized cell in the form of a horizontal or vertical box.
  • wx.StaticBoxSizer: This sizer of panel class will add a static text box around the Box sizer placed in the GUI window.
  • wx.GridBagSizer: This sizer is used to control the explicitly positioned each added controls inside the grid. And, it is used for spanning over more than one row or column present inside the grid of GUI window.