Course Content
Python PySide6
About Lesson

In this Python PySide6 lesson we want to learn How to Create First GUI with Python & PySide6, first of all let’s talk about PySide6.

 

What is PySide6 ?

PySide6 (Qt for Python) is Python binding for the cross-platform graphical user interface (GUI) toolkit Qt. It is a powerful tool that can be used to develop desktop applications that are compatible with multiple operating systems such as Windows, Linux, and macOS.

 

 

Getting Started with PySide6

To get started with PySide6, you will need to install it on your system. You can do this by running the following command in your terminal:

Once you have installed PySide6, you can begin creating your first window.

 

 

Let’s Create Basic Window with PySide6

for creating basic window in PySide6, you will need to create QApplication object and QMainWindow object. The QApplication object is responsible for managing application’s event loop, while the QMainWindow object is the main window of the application.

 

 

This is a simple code to create your first GUI Window with PySide6:

In the above code, we first imported the necessary modules from PySide6. after that we create QApplication object and QMainWindow object. QMainWindow object is assigned to the window variable.

Finally, we call the show() method to display window and the sys.exit() method to start the application’s event loop.

 

 

Run the code and this will be the result.

How to Create First GUI with Python & PySide6
How to Create First GUI with Python & PySide6

 

 

Customizing the Window

Now that we have created basic window in PySide6, we can customize it to suit our needs. we can add widgets such as buttons, labels, and text boxes, and also we can modify the window’s appearance by changing its size, title, and background color.

This is the code that show you how to change the window’s title and size:

In the above code, we have added two new lines. The first line sets window’s title to “GeeksCoders.com – PySide6 Course,” and the second line sets window’s geometry to (100, 100, 500, 500), which specifies the window’s position on the screen (100 pixels from the left and 100 pixels from the top) and its size (500 pixels wide and 500 pixels high).

 

 

 

Run the complete code and this will be the result.

How to Create First GUI with Python & PySide6
How to Create First GUI with Python & PySide6