wxpython — Major Classes

wxpython — Major Classes

The original wxWidgets is written in the C++ programming language and it has a huge library for classes. The classes are used for building GUI using wxWidgets of this library. These widgets are ported to our Python program through the wxpython module.

Therefore, the frame class present of the wxpython module acts same way as the wxFrame class acts in the C++ version of it.

The wxObject is the base of the most of the classes that are present in the wxpython module.

An object for the wxApp (The wxApp is used for the applications build of the wxpython module) represents the applications build by itself. After running the Python program, when the GUI window is generated, the application enters into an event loop through the loop method i.e., Mainloop() that we have defined in our Python program.

We have various different classes in our wxpython module. These classes also have sub-classes present in them. We will talk about some of the classes of wxpython module and sub-classes present in them. We will also look at which classes have exact similar functionality as of classes present in wxWidgets written in C++.

In this tutorial, we will discuss about the following classes present in the wxpython module and will look at the sub-classes present in them:

1. wxWindow

2. wxGDIObject

3. WxDC

4. WxSizer

5. WxControl

6. WxButton

Let’s look at each of them one by one and see what important sub-classes are present in them and how similar functionality they have with wxWidgets classes.

1. wxWindow class in wxpython module:

The wxWindow class is used to display the GUI window in the output of the program. This class have exact same functionality as those of window class present in the wxWidgets present in C++.

Following are the sub-classes that are present in the wxWindow class of wxpython module:

  • wxTopLevel Window
  • wxControl
  • wxPanel
  • wxStatusBar
  • wxMenuBar

From the above sub-classes, the ‘wxTopLevel Window’ class have further distribution of class. Let’s look at the distribution of sub-classes present in the ‘wxTopLevel Window’ class:

  • wxTopLevel Window Class: The wxTopLevel Window class is very important class of the wxpython module for displaying GUI window in the output. The class has the functionality to control the frame and dialog box appear in the GUI on our screen. The wxTopLevel Window Class consists of following two sub-classes:
  • wxFrame class
  • wxDialog class

Further, these two classes have sub-classes present in them also which control their own functionality in the GUI. We will look at them and understand how they are helpful while building an interactive GUI with the help of wxpython module in our Python program.

a. wxFrame class of wxpython module: The wxFrame class acts same as the Frame class present in the original wxWidgets have in C++.

This is the frame class of wxpython module that we have studied in the previous parts of this tutorial. This class is used to control the frame shown in the GUI window displayed in the output of program.

The frame class of wxpython module i.e., wxFrame have further following sub-classes present in it which are having their own functionalities according to the requirements of the GUI we are building:

  • wxPreviewFrame: This class is used to preview the frame that we are creating for our GUI through wxFrame class.
  • wxSplashScreen: This class is used to produce the splash onto the screen within the frame of GUI window using the frame class of wxpython module.
  • wxMiniFrame: This class is used to make the frame comparatively smaller or mini in the GUI window.
  • wxMDIParent: This class of wxpython module is used within the frame class when we define the parent function in the frame class. It is used to control the parent function within our Python program.
  • wxMDIChild: This class of wxFrame is used when we define a child function for the frame class in our Python program. It is used for controlling or inheriting the properties to the child function in our Python program using the parent function we defined in the frame class of wxpython module.

b. wxDialog class of wxpython module: The wxDialog class also acts same as the Dialog class present in the original wxWidgets have in C++.

Like the wxFrame class, the wxDialog class is used to control the Dialog box appears in the GUI window displayed in the output of our Python program. The dialog class of wxpython module can control and modify all the dialogs that are appearing on the GUI screen.

  • The dialog class of wxpython module have the following functionalities:
  • Controlling the dialog box appears on the GUI screen
  • Modifying the dialogue appearing on the GUI screen
  • Editing the dialog box appears on the GUI screen etc.

The wxDialog class of wxpython module have further sub-classes that are used to control the functionality of Dialog class according to the requirement for the GUI window that we are building. The sub-classes of wxDialog class are very helpful when we are building an interactive GUI through wxpython module. Following are the sub-classes that are present in the wxDialog class of wxpython module:

  • wxFileDialog: This class is used to control the system file where we have defined the functions of dialog box through the dialog class.
  • wxDirDialog: This class is used to control the system directory where we have defined the functions of dialog box through the dialog class.
  • wxColourDialog: This class is used to control the colour of the dialog box that appears on the GUI screen. We can modify or edit the colour of the dialog box using this ‘wxColourDialog’ class.
  • wxMessageDialog: This class is used to control the message shown in the dialog box that appears on the GUI screen. We can modify or edit the message shown in the dialog box using this ‘wxMessageDialog’ class.
  • wxFontDialog: This class is used to control the font of the message shown in the dialog box that appears on the GUI screen. We can modify or edit font of the message shown in the dialog box using this ‘wxFontDialog’ class.
  • wxTextEntry: This class is used to enter the text or message in the dialog box that we want to appears on the GUI screen in the form of a dialog.

2. wxGDIObject class:

The wxGDIObject class of wxpython module is very useful in creating multiple objects for the GUI window. We can use this class whenever we want to add an object like image, text, Icon etc. in our GUI screen. The GDI object class of wxpython module acts in very similar way as that wxGDIObject class of original wxWidgets acts in the C++.

The wxGDIObject can control multiple objects in the GUI screen shown in the output of the program with the help of its various sub-classes. We will look at these sub-classes and see their functionality in our Python program for building GUI.

Following are the sub-classes that are present in wxGDIObject along with their functionalities in the wxpython module:

  • wxBitmap: This class is used to add the Bitmap image in the GUI screen. We can add various types of images of various resolutions using this class. The wxBitmap class of wxpython module can also be used to modifying those images and changing their appearance in the GUI screen.
  • wxBrush: This class is used to add the Brush in the GUI screen. We can add various types of brushes having various sizes and shapes using this class. The wxBrush class of wxpython module can also be used to modifying those brushes and changing their appearance in the GUI screen.
  • wxFont: This class is used to add the text of various fonts in the GUI screen. We can add text with various types of fonts of different style using this class. The wxFont class of wxpython module can also be used to modifying those fonts of the text in the GUI screen.
  • wxIcon: This class is used to add the Icons in the GUI screen. We can add various types of Icons (such as symbol representing numbers etc.) having various sizes and styles using this class. The wxIcon class of wxpython module can also be used to modifying those icons and changing their appearance in the GUI screen.
  • wxPen: This class is used to add the Pen in the GUI screen. We can add various types of pen having various sizes and shapes using this class. The wxPen class of wxpython module can also be used to modifying those pens and changing their appearance in the GUI screen.

3. wxDC class of wxpython module:

The wxDC class is used to connect the GUI screen that we have built with various items present in our system where we are building GUI. We can connect the GUI screen to following items from our system:

  • Screen of system
  • Printer of system
  • Paint of system etc.

We can do this connection of items with GUI screen with the help of various sub-classes present in the wxDC class. Following are the sub-classes that are present in the wxDC class of wxpython module along with their functionalities:

  • wxScreenDC: This class is used to connect the screen of our system with the GUI screen that we have built through wxpython module.
  • wxPaintDC: This class is used to connect the paint present in our system with the GUI screen that we have built through wxpython module.
  • wxWindowDC: This class is used to connect the window of our system with the GUI screen that we have built through wxpython module.
  • wxPrinterDC: This class is used to connect the printer option present in our system with the GUI screen that we have built through wxpython module.

4. wxSizer:

The wxSizer class of wxpython module is used to control the each added control in the GUI screen. The sizer class control the size of the control we are adding to the GUI screen. It also controls the layout of the controls by which they will show in the GUI screen. The sizer class of wxpython module can place the each added control in the GUI screen in the form of the one of the two following given screen layouts:

  • Box Layout
  • Grid Layout

The wxSizer class can do this classification of layout in the GUI screen with the following two sub-classes present in it:

a. wxBoxSizer

b. wxGridSizer

a. wxBoxSizer: we can use this class to place the each added control in the GUI screen in the form of Box Layout i.e., Horizontal box and Vertical box. We have the following sub-classes present in the wxBoxSizer class of wxpython module through which we can control the Box Layout of the GUI screen:

  • wxStaticBoxSizer
  • wxStdDialogButton
  • wxWrapSizer

b. wxGridSizer: we can use this class to place the each added control in the GUI screen in the form of Grid Layout i.e., in the form of rows and columns (table) layout. We have the following sub-classes present in the wxGridSizer class of wxpython module through which we can control the Grid Layout of the GUI screen:

  • wxFlexiGridSizer
  • wxGridBagSizer

5. wxControl class of wxpython module:

The wxControl class of wxpython module is used to add various controls in the GUI screen that we have built. The wxControl class of wxpython module acts same as of Control class of original wxWidgets library of C++.

We can add the following controls in the GUI screen with the help of wxControl class:

  • Check Box
  • Gauge
  • Combo Box
  • Radio Button
  • Text controller
  • Static Text
  • Slider
  • Scroll Bar
  • Spin Controller

We can add these controls in the GUI screen that we have build with the help of sub-classes of wxControl class. Following are sub-classes of wxControl class through which we can add the above-mentioned controls in the GUI screen:

  • wxCheckBox
  • wxGauge
  • wxComboBox
  • wxRadioButton
  • wxTextCtrl
  • wxStaticText
  • wxSlider
  • wxScrollBar
  • wxSpinCtrl

6. wxButton class of wxpython module:

The wxControl class of wxpython module is used to add two types of button in the GUI screen that we have built. The wxButton class of wxpython module acts same as of Button class of original wxWidgets library of C++.

We can add the following two types of button in the GUI screen with the help of wxButton class:

  • Bitmap Button
  • Command Link Button

We can add these buttons in the GUI screen that we have built with the help of sub-classes of wxControl class. Following are sub-classes of wxControl class through which we can add the above-mentioned two types of buttons in the GUI screen:

  • wxBitmapButton
  • wxCommandLinkButton

These are the classes that are present in wxpython module library present in Python and they have sub-categorised according to the functionality of these classes that are used for building an interactive GUI.

https://www.tutorialandexample.com/python-program-to-check-if-two-strings-are-anagram-or-not/