PyQt6 Tutorial Series | Python GUI Programming

This article is the first in a tutorial series on the python GUI library, PyQt6.

PyQt is actually derived from the famous cross-platform GUI library, Qt. It is the result of combining the versatile Python language with the powerful Qt library. In more technical terms, PyQt6 is a wrapper around the Qt6 library. With the help of PyQt6 (it’s latest version) we can create modern, portable and stylish GUI’s for our Python programs.

Another popular alternative you can use is the Python Tkinter library. While being simple and easy to learn, it is often criticized for it’s rather outdated look and limited features. PyQt6 is considered the more modern GUI library, and this is something we will demonstrate in this Tutorial.


Introduction to PyQt6

Unless you have some basic/prior knowledge about PyQt6 already, go through this PyQt6 setup tutorial first. It explains the very basic commands used to install, start PyQt6, and how to setup a basic window. (Also known as the boiler plate code).

Since you’ll find the same commands repeated in every PyQt6 program in the tutorials below, you can skip it if you want, but then you won’t get the proper explanation behind those commands. (no point in just copy pasting code you don’t understand right?)

Once you’ve understood how to use a few widgets in PyQt6, be sure to check out Layout management in PyQt6. Knowing how to create, customize and use PyQt6 widgets is just the foundation. Learning how to position them correctly within the GUI Window is extremely important.


List of PyQt6 QWidgets

A list of widgets that we will be covering in this PyQt6 Tutorial Series. (Click on the links to head to their respective tutorials)

QLabel Widget – A basic “bread and butter” kind of widget, used to display lines of text on the GUI window. This widget comes bundled with many supporting functions and methods, allowing us to retrieve and update the displayed text easily.

QPushButton – One of the most basic and common widgets in PyQt6. Creates a button that is linked to a function. Clicking on the button will cause the linked function to execute.

QLineEdit – Another very common widget used to take input from the User. Out of all the input methods in PyQt6, the most common way is through the QLineEdit widget. It offers you a single line where the User can enter Text.

QRadioButton – Radio Buttons are used in GUI applications when we need to present the user with a list of options. Only one Radio Button option can be selected at a given point.

QCheckBox – A Checkbox is an important part of any GUI, used when you want to present the User with a list of options. Unlike Radio buttons, you are allowed to select multiple Checkboxes, or even none at all.

QComboBox – The ComboBox widget in PyQt6 is used to display a drop-down list of options, which the user can select any option from. The advantage of this widget is that it takes up very little space on the screen, making it suitable for smaller GUI windows.

QTextEdit – Like the QLineEdit widget, QTextEdit is used to take input from the user in the form of text. Unlike QLineEdit however, QTextEdit takes multiline input, allowing for entire paragraphs to be entered.

QMessageBox – A useful widget used to create GUI prompts and dialogs. These dialogs can customized to have different messages, icons and button options.

QSlider – This widget provides an interactive slider which the user may interact with to select from a range of values. PyQt6 allows us to customize the slider and it’s many values, such as changing its range of values, it’s intervals between values, as well as the size of the slider head (and more!)

QProgressBar – Progress bars is a great way to visualize progression of tasks such as file transferring, downloading, uploading, copying etc.

For further customization of your PyQt6 application, you can explore the concept of “PyQt Themes“. These allow you to create templates which control the look and feel of your application, and can be dynamically switched during run-time (e.g. dark mode).


Further Reading

You might want to refer back to the original PyQt5 resource at some point (e.g: Migration purposes), so here is a link to our PyQt5 version of this tutorial series.

Looking for PyQt Alternatives? This article here discusses two of the most popular Python GUI libraries, Tkinter and wxPython.


This marks the end of our very first Tutorial on PyQt6. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below..

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments