The complete PyQt5 course — Create GUI applications with Python

Easily create professional-quality desktop applications for Windows, Mac and Linux. Unlock the power of Qt5 from Python with PyQt.

Create GUI Applications with PyQt

PyQt is a Python library for creating GUI applications using the Qt toolkit. Created by Riverbank Computing, PyQt is free software (GPL licensed) and has been in development since 1999. The latest version PyQt6 -- based on Qt 6 -- was released in 2021 and the library continues to be updated.

There are two major versions currently in use: PyQt5 based on Qt5 and PyQt6 based on Qt6. Both versions are almost completely compatible aside from imports, and lack of support for some advanced modules in Qt6. PyQt6 also makes some changes to how namespaces and flags work, but these are easily manageable.

In this complete PyQt5 course we'll learn how to use PyQt to create desktop applications with Python.

PyQt5 not installed? Check out the installation guides for Windows, Linux and Mac.

This course includes 34 tutorials.

Getting started with PyQt5

Like writing any code, building PyQt5 applications is all about approaching it in the right way. In the first part of the course we cover the fundamentals necessary to get you building Python GUIs as quickly as possible. By the end of the first part you'll have a running QApplication which we can then customize.


Take your first steps building apps with Python & Qt5

Creating applications with Qt Designer

As your applications get larger or interfaces become more complicated, it can get a bit cumbersome to define all elements programmatically. The good news is that Qt comes with a graphical editor Qt Designer (or Qt Creator) which contains a drag-and-drop UI editor — Qt Designer. In this PyQt5 tutorial we'll cover the basics of creating Python GUIs with Qt Designer.


Using the drag-drop designer to develop your apps

Extended UI features

The topics we've covered so far are enough to build perfectly functional desktop applications with PyQt. In this chapter we'll take a look at some more technical and lesser-known aspects of the Qt framework to gain a deeper understanding of how things work.


Extending your apps with complex GUI behaviour

Mozzarella Ashbadger

Now we've learnt the basics, we'll put it into practice building a real-life app. In this course we'll create a functional web browser using Qt5 widgets. Starting with the basics and then gradually extending it to add features like opening and saving pages, help, printing and tabbed browsing. Follow the tutorial step by step to create your own app, but feel free to experiment as you go.


Build your own tabbed web browser with PyQt5

Threads & Processes

The event loop started by calling .exec_() on your QApplication object runs within the same thread as your Python code. The thread which runs this event loop — commonly referred to as the GUI thread — also handles all window communication with the host operating system.

By default, any execution triggered by the event loop will also run synchronously within this thread. In practice this means that any time your PyQt application spends doing something in your code, window communication and GUI interaction are frozen.

If what you're doing is simple, and returns control to the GUI loop quickly, this freeze will be imperceptible to the user. However, if you need to perform longer-running tasks, for example opening/writing a large file, downloading some data, or rendering some complex image, there are going to be problems. To your user the application will appear to be unresponsive. Because your app is no longer communicating with the OS the OS will think it has crashed -- on macOS you see the spinning wheel of death, on Windows the window will dim. That's not a good look.

The solution is simple -- get your work out of the GUI thread. PyQt provides straightforward interfaces to accomplish exactly that.


Run concurrent tasks without impacting your UI

Create GUI Applications with Python & Qt (PyQt6 Edition)
The easy way to create desktop applications

Create GUI Applications is the complete guide to building GUI applications with Python. Starting from the very basics of creating a desktop window this book takes you on a tour of the key features of PyQt5 you can use to build real-life applications.

Downloadable ebook (PDF, ePub) & Complete Source code

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

[[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount on all books and courses.

ModelViews and Databases

As you start to build more complex applications with PyQt you'll likely come across issues keeping widgets in sync with your data.

Data stored in widgets (e.g. a simple QListWidget) is not easy to manipulate from Python — changes require you to get an item, get the data, and then set it back. The default solution to this is to keep an external data representation in Python, and then either duplicate updates to the both the data and the widget, or simply rewrite the whole widget from the data. As you start to work with larger data this approach can start to have performance impacts on your application.

Thankfully Qt has a solution for this — ModelViews. ModelViews are a powerful alternative to the standard display widgets, which use a standardized model interface to interact with data sources — from simple data structures to external databases. This isolates your data, meaning you can keep it in any structure you like, while the view takes care of presentation and updates.

In this next part of the PyQt5 course we'll discover how you can use Qt ModelViews to build high performance Python GUIs.


Connecting your application to data sources

Graphics and Plotting

One of the major strengths of Python is in data science and visualization, using tools such as Pandas, numpy and sklearn for data analysis. Buiding GUI applications with PyQt gives you access to all these Python tools directly from within your app, allowing you to build complex data-driven apps and interactive dashboards. We've already covered the model views, which allow us to show data in lists and tables. In this chapter we'll look at the final piece of that puzzle -- plotting data.

When building apps with PyQt you have two main choices -- matplotlib (which also gives access to Pandas plots) and PyQtGraph, which creates plots with Qt-native graphics. In this chapter we'll look at how you can use these libraries to visualize data in your applications.


Vector graphics and plotting using PyQtGraph

Custom Widgets

As we've seen, Qt comes with a wide range of widgets built-in, which you can use to build your applications. Even so, sometimes these simple widgets are not enough -- maybe you need an input for some custom types, or want to visualize data in a unique way. In Qt you are free to create your own widgets, either from scratch or by combining existing widgets.

Widgets in Qt are built on bitmap graphics — drawing pixels on a rectangular canvas to construct the "widget". To be able to create your own custom widgets you first need to understand how the QPainter system works and what you can do with it. In this PyQt5 tutorial we'll go from basic bitmap graphics to our own entirely custom widget.


Designing your own custom widgets in PyQt

Packaging and distribution

There comes a point in any app's development where it needs to leave home — half the fun in writing software is being able to share it with other people. Packaging Python GUI apps can be a little tricky, but in this PyQt5 tutorial we'll cover how to package up your apps to share, whether commercially or just for fun.


Sharing your awesome applications with other people

QtQuick & QML

Qt Quick is Qt's declarative UI design system, using the Qt Modeling Language (QML) to define custom user interfaces. Originally developed for use in mobile applications, it offers dynamic graphical elements and fluid transitions and effects allowing you to replicate the kinds of UIs you find on mobile devices. Qt Quick is supported on all desktop platforms too and is a great choice for building desktop widgets or other interactive tools. Qt Quick is also a great choice for developing UIs for hardware and microcontrollers.


Building modern GUIs with QtQuick & QML