layout = QGridLayout() layout.addWidget(QLabel("Name:"), 0, 0) layout.addWidget(QLineEdit(), 0, 1) layout.addWidget(QLabel("Email:"), 1, 0) layout.addWidget(QLineEdit(), 1, 1) Override built-in event handlers or connect signals.
This guide will walk you through the essentials of PyQt6, from installation to building your first interactive app. Install PyQt6 using pip:
window.setLayout(layout) window.show()
| Layout | Purpose | |--------|---------| | QHBoxLayout | Horizontal arrangement | | QVBoxLayout | Vertical arrangement | | QGridLayout | Grid (row/column) layout | | QFormLayout | Label–field pairs |
from PyQt6.QtWidgets import QMessageBox def show_info(): QMessageBox.information(window, "Title", "This is an info message.") You can design UIs visually using Qt Designer (included with Qt tools) and load .ui files in Python: how to use pyqt6
layout.addWidget(label) layout.addWidget(button)
class MyWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Event Demo") def mousePressEvent(self, event): print(f"Mouse clicked at (event.pos().x(), event.pos().y())") Use QMessageBox , QInputDialog , or custom dialogs. layout = QGridLayout() layout
import PyQt6 print(PyQt6.__version__) # e.g., 6.6.0 Let's create a basic empty window.