PyQt5

5.15.11 · active · verified Fri Apr 10

PyQt5 is a comprehensive set of Python bindings for the Qt cross-platform application toolkit, enabling developers to create graphical user interfaces (GUIs) for desktop and mobile systems. It leverages the robust C++ Qt framework, providing high-level APIs for UI development, multimedia, networking, databases, and more. The current stable version is 5.15.11, maintained by Riverbank Computing Ltd. While PyQt5 is mature and stable, its successor, PyQt6, is available, targeting Qt6.

Warnings

Install

Imports

Quickstart

This quickstart creates a simple PyQt5 window displaying 'Hello, PyQt5!' in a centrally aligned label. It demonstrates the basic structure of a PyQt5 application, including creating an QApplication instance, defining a main window (subclassing QWidget), adding a QLabel, setting layout, and starting the application's event loop.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5.QtCore import Qt

class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('PyQt5 Hello World')
        self.setGeometry(100, 100, 400, 200) # x, y, width, height

        layout = QVBoxLayout()
        self.label = QLabel('Hello, PyQt5!', self)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setStyleSheet("font-size: 24px; color: blue;")

        layout.addWidget(self.label)
        self.setLayout(layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())

view raw JSON →