PySide2

5.15.2.1 · maintenance · verified Thu Apr 16

PySide2 provides the official Python bindings for the Qt cross-platform application and UI framework, specifically for Qt5. It enables Python developers to create robust desktop graphical user interfaces. As of version 5.15.2.1, PySide2 is primarily in maintenance mode, with active development having shifted to PySide6 for Qt6. Releases are less frequent now compared to PySide6.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart code creates a basic PySide2 application that displays a window with a 'Hello, PySide2 World!' label. It demonstrates the fundamental steps: creating a QApplication instance, a QWidget as the main window, adding a QLabel, and starting the application's event loop using `app.exec_()` to keep the window open.

import sys
from PySide2.QtWidgets import QApplication, QWidget, QLabel

if __name__ == '__main__':
    app = QApplication(sys.argv)

    # Create a Qt widget, which will be our window.
    window = QWidget()
    window.setWindowTitle('Hello PySide2')
    window.setGeometry(100, 100, 280, 80)

    # Create a label and set its text
    label = QLabel('Hello, PySide2 World!', parent=window)
    label.move(60, 30)

    window.show()  # IMPORTANT!!!!! Windows are hidden by default.

    sys.exit(app.exec_()) # Start the event loop.

view raw JSON →