The complete PySide6 tutorial — Create GUI applications with Python

The easy way to create desktop applications

Last updated

Create Desktop GUI Applications with PySide6

PySide, also known as Qt for Python, is a Python library for creating GUI applications using the Qt toolkit. PySide is the official binding for Qt on Python and is now developed by The Qt Company itself.

This complete PySide6 tutorial takes you from first concepts to building fully-functional GUI applications in Python. It requires some basic Python knowledge, but no previous familiarity with GUI concepts. Everything will be introduced step by by step, using hands-on examples.

PySide6 is the Qt6-based edition of the Python GUI library PySide from The Qt Company.

There are two major versions currently in use: PySide2 based on Qt5 and PySide6 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.

Looking for something else? I also have a PyQt5 tutorial, PyQt6 tutorial and PySide2 tutorial.

This track consists of 20 tutorials. Keep checking back as I'm adding new tutorials regularly — last updated .

Getting started with PySide6

Take your first steps building Python & Qt6 apps with PySide6

Like writing any code, building PySide6 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.

Creating your first app with PySide6
A simple Hello World! application with Python and Qt

In this tutorial we'll learn how to use PySide to create desktop applications with Python. First we'll create a series of simple windows on your desktop to ensure that PySide is working and introduce some of the basic concepts. Then we'll take a brief look at the event loop and how it relates to GUI programming in Python. Finally we'll look at Qt's QMainWindow which offers some useful common interface elements such as toolbars and menus. These will be explored in more detail in the subsequent tutorials.

Start now Complete

PySide6 Signals, Slots & Events
Triggering actions in response to user behaviors and GUI events

So far we've created a window and added a simple push button widget to it, but the button doesn't do anything. That's not very useful at all -- when you create GUI applications you typically want them to do something! What we need is a way to connect the action of pressing the button to making something happen. In Qt, this is provided by signals and slots or events.

Start now Complete

PySide6 Widgets
Using PySide6's built-in widgets to build your applications

In Qt (and most User Interfaces) ‘widget’ is the name given to a component of the UI that the user can interact with. User interfaces are made up of multiple widgets, arranged within the window.

Start now Complete

PySide6 Layouts
Use layouts to effortlessly position widgets within the window

So far we've successfully created a window, and we've added a widget to it. However we normally want to add more than one widget to a window, and have some control over where it ends up. To do this in Qt we use layouts. There are 4 basic layouts available in Qt, which are listed in the following table.

Start now Complete

PySide6 Toolbars & Menus — QAction
Defining toolbars, menus and keyboard shortcuts with QAction

Next we'll look at some of the common user interface elements, that you've probably seen in many other applications — toolbars and menus. We'll also explore the neat system Qt provides for minimising the duplication between different UI areas — QAction.

Start now Complete

PySide6 Dialogs and Alerts
Notify your users and ask for their input

Dialogs are useful GUI components that allow you to communicate with the user (hence the name dialog). They are commonly used for file Open/Save, settings, preferences, or for functions that do not fit into the main UI of the application. They are small modal (or blocking) windows that sit in front of the main application until they are dismissed. Qt provides a number of 'special' built-in dialogs for the most common use-cases, allowing you to provide a platform-native user experience.

Start now Complete

Creating additional windows
Opening new windows for your application

In an earlier tutorial we've already covered how to open dialog windows. These are special windows which (by default) grab the focus of the user, and run their own event loop, effectively blocking the execution of the rest of your app.

Start now Complete

Creating applications with Qt Designer

Using the drag-drop designer to develop your PySide apps

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 PySide6 tutorial we'll cover the basics of creating Python GUIs with Qt Designer.

First steps with Qt Designer
Use Qt Designer's drag and drop interface to design your GUI

So far we have been creating apps using Python code. This works great in many cases, but as your applications get larger or interfaces more complicated, it can get a bit cumbersome to define all widgets programmatically. The good news is that Qt comes with a graphical editor — Qt Designer — which contains a drag-and-drop UI editor. Using Qt Designer you can define your UIs visually and then simply hook up the application logic later.

Start now Complete

The QResource System
Using the QResource system to package additional data with your applications

Building applications takes more than just code. Usually your interface will need icons for actions, you may want to add illustrations or branding logos, or perhaps your application will need to load data files to pre-populate widgets. These data files are separate from the source code of your application but will ultimately need to be packaged and distributed with it in order for it to work.

Start now Complete

Extended UI features

Extending your PySide apps with complex GUI behaviour

In this PySide6 tutorial we'll cover some advanced features of Qt that you can use to improve your Python GUIs.

Transmitting extra data with Qt Signals
Modifying widget signals to pass contextual information to slots

Signals are a neat feature of Qt that allow you to pass messages between different components in your applications. Signals are connected to slots which are functions (or methods) which will be run every time the signal fires. Many signals also transmit data, providing information about the state change or widget that fired them. The receiving slot can use this data to perform different actions in response to the same signal.

Start now Complete

System tray & Mac menu bar applications
Add quick access functions to your apps

System tray applications (or menu bar applications) can be useful for making common functions or information available in a small number of clicks. For full desktop applications they're a useful shortcut to control apps without opening up the whole window.

Start now Complete

Threads & Processes

Run concurrent tasks without impacting your PySide UI

As your applications become more complex you may finding yourself wanting to perform long-running tasks, such as interacting with remote APIs or performing complex calculations. By default any code you write exists in the same thread and process, meaning your long-running code can actually block Qt execution and cause your Python GUI app to "hang". In this PySide6 tutorial we'll cover how to avoid this happening and keep your applications running smoothly, no matter the workload.

Multithreading PySide6 applications with QThreadPool
Run background tasks concurrently without impacting your UI

A common problem when building Python GUI applications is "locking up" of the interface when attempting to perform long-running background tasks. In this tutorial I'll cover one of the simplest ways to achieve concurrent execution in PySide6.

Start now Complete

Using QProcess to run external programs
Run background programs without impacting your UI

So far we've looked at how to run work in separate threads, allowing you to do complex tasks without interrupting your UI. This works great when using Python libraries to accomplish tasks, but sometimes you want to run external applications, passing parameters and getting the results.

Start now Complete

ModelViews and Databases

Connecting your PySide application to data sources

All but the simplest of apps will usually need to interact with some kind of external data store — whether that's a database, a remote API or simple configuration data. The Qt ModelView architecture simplifies the linking and updating your UI with data in custom formats or from external sources. In this PySide6 tutorial we'll discover how you can use Qt ModelViews to build high performance Python GUIs.

The ModelView Architecture
Qt's MVC-like interface for displaying data in views

As you start to build more complex applications with PySide6 you'll likely come across issues keeping widgets in sync with your data. Data stored in widgets (e.g. a simple QListWidget) is not readily available 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. This can get ugly quickly, and results in a lot of boilerplate just for fiddling the data.

Start now Complete

Displaying tabular data in Qt ModelViews
Create customized table views with conditional formatting, numpy and pandas data sources.

In the previous chapter we covered an introduction to the Model View architecture. However, we only touched on one of the model views — QListView. There are two other Model Views available in Qt5 — QTableView and QTreeView which provide tabular (Excel-like) and tree (file directory browser-like) views using the same QStandardItemModel.

Start now Complete

Graphics and Plotting

Vector graphics and plotting using PyQtGraph in PySide6

Python is one of the most popular languages in the data science and machine learning fields. Effective visualization of data is a key part of building usable interfaces for data science. Matplotlib is the most popular plotting library in Python, and comes with support for PySide built in. In addition, there are PySide6 specific plotting options available such as PyQtGraph which provide a better interactive experience. In this tutorial we'll look at these alternatives and build some simple plot interfaces.

This course is not yet ready to take, but I'm working on it. Check back shortly.

Custom Widgets

Designing your own custom widgets in PySide6

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 PySide6 tutorial we'll go from basic bitmap graphics to our own entirely custom widget.

QPainter and Bitmap Graphics
Introduction to the core features of QPainter

The first step towards creating custom widgets in PyQt5 is understanding bitmap (pixel-based) graphic operations. All standard widgets draw themselves as bitmaps on a rectangular "canvas" that forms the shape of the widget. Once you understand how this works you can draw any widget you like!

Start now Complete

Creating custom GUI widgets in PySide6
Build a completely functional custom widget from scratch using QPainter

In the previous tutorial we introduced QPainter and looked at some basic bitmap drawing operations which you can used to draw dots, lines, rectangles and circles on a QPainter surface such as a QPixmap.

Start now Complete

Animating custom widgets with QPropertyAnimation
Add dynamic visual effects to your custom widgets

In the previous tutorial we looked at how you can build custom widgets with PySide6. The widget we built used a combination of layouts, nested widgets and a simple QPainter canvas to create a customized widget you can drop into any application.

Start now Complete

Packaging and distribution

Sharing your PySide6 applications with other people

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 PySide6 tutorial we'll cover how to package up your apps to share, whether commercially or just for fun.

This course is not yet ready to take, but I'm working on it. Check back shortly.

QtQuick & QML

Building modern PySide6 GUIs with 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 with PySide6.

Create applications with QtQuick
Build modern applications with declarative QML

In previous tutorials we've used the Qt Widgets API for building our applications. This has been the standard method for building applications since Qt was first developed. However, Qt provides another API for building user interfaces: Qt Quick. This is a modern mobile-focused API for app development, with which you can create dynamic and highly customizable user interfaces.

Start now Complete

Animations and Transformations with QtQuick
Building an animated analog clock in QML

In the previous tutorial we implemented a basic QML clock application using Python code to get the current time, format it into a string and send that through to our QML layout for display using Qt signals.

Start now Complete