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.
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 your first app with PyQt
A simple Hello World! application with Python and Qt5
Signals, Slots & Events
Triggering actions in response to user behaviors and GUI events
Using Qt5's library of built-in widgets to build your applications
Use layouts to effortlessly position widgets within the window
Actions — Toolbars & Menus
Defining toolbars, menus and keyboard shortcuts with QAction
Dialogs and Alerts
Notify your users and ask for their input
Creating additional windows
Opening new windows for your application
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
First steps with Qt Designer
Use Qt Designer's drag and drop interface to design your GUI
Laying Out Your GUIs With Qt Designer
Use Qt Designer to effortlessly build your application UI
Embedding custom widgets from Qt Designer
Learn how to use custom widgets in your PyQt5 applications when designing with Qt Designer
Creating Dialogs With Qt Designer
Using the drag and drop editor to build PyQt5 dialogs
The QResource System
Using the QResource system to package additional data with your applications
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
System tray & Mac menu bar applications
Add quick access functions to your apps
Add scrollable regions with QScrollArea
Run out of space in your GUI? Add a scrollable region to your application
Creating searchable widget dashboards
Make dashboard UIs easier to use with widget search & text prediction
Transmitting extra data with Qt Signals
Modifying widget signals to pass contextual information to slots
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
The first steps building the browser with PyQt5
Adding navigational controls to a PyQt5 Web Browser
Hook up QAction signals to web browser slots
Open and save HTML in a PyQt5 browser
Adding file dialogs to load and save HTML
Adding application Help and About dialogs
Put some finishing touches to your application
Tabbed web browsing
Use signal redirection to add a multi-tab interface
The event loop started by calling
.exec_() on your
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 (PyQt5 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.
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.
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
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
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
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
QPainter and Bitmap Graphics
Introduction to the core features of QPainter
Creating custom GUI widgets in PyQt5
Build a completely functional custom widget from scratch using QPainter
Animating custom widgets with QPropertyAnimation
Add dynamic visual effects to your custom widgets
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
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.