PyQt6's extensive widget library allows building professional, cross-platform desktop applications with native look and feel. The combination of layout managers, signals/slots, and style sheets gives you complete control over both behavior and appearance.
from PyQt6.QtWidgets import * from PyQt6.QtCore import Qt layout = QHBoxLayout() layout.addWidget(QLabel("Name:")) layout.addWidget(QLineEdit()) layout.setStretchFactor(layout.itemAt(1).widget(), 1) # Text field expands Every widget emits signals (events) that connect to other widget methods or custom functions: pyqt6 widgets
def show_text(self): text = self.line.text() if text: self.label.setText(f"You typed: text") else: self.label.setText("Nothing typed!") pyqt6 widgets
central = QWidget() self.setCentralWidget(central) layout = QVBoxLayout(central) # Input widgets self.line = QLineEdit() self.line.setPlaceholderText("Type something...") self.btn = QPushButton("Show Text") self.btn.clicked.connect(self.show_text) self.label = QLabel("Result will appear here") self.label.setAlignment(Qt.AlignmentFlag.AlignCenter) # Selection widgets self.combo = QComboBox() self.combo.addItems(["Option A", "Option B", "Option C"]) self.combo.currentTextChanged.connect(self.update_combo_label) self.combo_label = QLabel("Selected: Option A") layout.addWidget(self.line) layout.addWidget(self.btn) layout.addWidget(self.label) layout.addWidget(self.combo) layout.addWidget(self.combo_label) pyqt6 widgets
def update_combo_label(self, text): self.combo_label.setText(f"Selected: text") app = QApplication(sys.argv) window = DemoWindow() window.show() sys.exit(app.exec()) | Use Case | Recommended Widget | |--------------|------------------------| | Simple text input | QLineEdit | | Multi-line text | QTextEdit | | Numeric bounded input | QSpinBox | | Yes/No option | QCheckBox | | Exclusive choice (2-5 options) | QRadioButton + QButtonGroup | | Exclusive choice (many options) | QComboBox | | List of strings | QListWidget | | Table of editable data | QTableWidget | | Hierarchical data | QTreeWidget | | Progress indication | QProgressBar | | Form layout | QFormLayout + QLineEdit / QComboBox | | Image display | QLabel with QPixmap |
button = QPushButton("Click Me") label = QLabel("Not clicked") button.clicked.connect(lambda: label.setText("Clicked!"))