In this section, we are going to learn about GUI. Python has various frameworks for GUI. In this section, we are going to look at PyQt5. PyQt5 has different graphics components, also known as object widgets, which can be displayed on screen and also interact with users. The components are listed here:
- PyQt5 window: The PyQt5 window will create a simple app window.
- PyQt5 button: The PyQt5 button is a button that causes an action whenever it is clicked.
- PyQt5 textbox: The PyQt5 textbox widget allows users to enter the text.
- PyQt5 label: The PyQt5 label widget displays a single-line text or an image.
- PyQt5 combo box: The PyQt5 combo box widget is a combined button and a popup list.
- PyQt5 check box: The PyQt5 check box widget is an option button that can be checked and unchecked.
- PyQt5 radio button: The PyQt5 radio button widget is an option button that can be checked or unchecked. In a group of radio buttons, only one of the buttons can be checked at a time.
- PyQt5 message box: The PyQt5 message box widget display a message.
- PyQt5 menu: The PyQt5 menu widget gives different choices that are displayed.
- PyQt5 table: The PyQt5 table widget provides standard table display functionality for applications, which can be constructed with a number of rows and columns.
- PyQt5 signals/slots: Signals will let you react to the event that has occurred and slot is simply a function that gets called whenever a signal occurs.
- PyQt5 layouts: The PyQt5 layouts consist of multiple widgets.
There are several PyQt5 classes available, which are divided into different modules. These modules are listed here:
- QtGui: QtGui contains classes for event handling, graphics, fonts, texts, and basic imaging.
- QtWidgets: QtWidgets contains classes to create desktop-style user interfaces.
- QtCore: QtCore contains core non-GUI functionality such as time, directories, files, streams, URLs, data types, threads, and processes.
- QtBluetooth: QtBluetooth contains classes for connecting with devices and interacting with them.
- QtPositioning: QtPositioning contains classes to determine the position.
- QtMultimedia: QtMultimedia contains classes for APIs and multimedia content.
- QtNetwork: QtNetwork contains classes for network programming.
- QtWebKit: QtWebkit contains classes for web browser implementation.
- QtXml: QtXml contains classes for XML files.
- QtSql: QtSql contains classes for databases.
The GUI is driven by the events. Now, what is an event? An event is a signal that indicates that something has happened in your program, for example, menu selection, mouse movement, or button clicks. The events are handled by functions and triggered when a user performs some actions on the objects. The listener will listen to the event and then it will invoke an event handler whenever an event occurs.