Khalid M. Elboray

PySide6 Part 1

About the series

In this series i will cover the basics of PySide6 and how to use it to create a simple GUI Application in Python.

PySide6

PySide6 also known as Qt for Python is a cross-platform, open-source, GUI toolkit for Python.

PySide6 is the official binding for Qt on Python and is now developed by the Qt Company itself.

Getting Started With PySide6

In this tutorial we’ll learn how to use PySide6 to create Desktop applications in Python.

Creating an application

To create our first application, let’s create a python file called app.py and save it anywhere accessible.

and to use PySide6 we need to install it first.

python3 -m pip install PySide6

then we write a simple application in Python:

a simple PySide6 app should look like

from PySide6.QtWidgets import QApplication, QWidget

# import os module to access command line arguments
import os

# We need one (and only one) QApplication instance per application.
# Pass in sys.argv to allow command line arguments for your app.
# If you know you won't use command line arguments QApplication([]) is fine.

app = QApplication(sys.argv)

# Create a Qt Widget instance, witch will be the main window of our application
window = QWidget()

# And because the window is hidden by default, we need to show it
window.show()

# Start the event loop.
# You need to call this once your application is ready to receive events.
app.exec()

# Our application will run until quit() is called, which we do on the window being closed.
# So we won't actually get here until we close the window.

Now we have a simple application, we can run it by executing the following command:

python3 app.py

The application will run and you can see the window.

Walking through the code

Now let’s walk through the code and see how it works. so we understand what exactly is happening.

Enjoy Reading This Article?