Pyqt6 | Widgets

self.setWindowTitle("My App") self.setGeometry(100, 100, 400, 300)

# 1. Create the Application instance app = QApplication(sys.argv)

PyQt6 is a powerful set of Python bindings for the framework, enabling developers to build sophisticated, cross-platform desktop applications. At the heart of every PyQt6 application are widgets —the fundamental building blocks used to display information, accept user input, and provide interactive controls. The Role of Widgets in PyQt6

self.btn = QPushButton("Show Text") self.btn.clicked.connect(self.show_text) pyqt6 widgets

PyQt6 provides layout managers that automatically resize and reposition widgets when windows resize – eliminating hardcoded coordinates.

if __name__ == "__main__": main()

# Selection widgets self.combo = QComboBox() self.combo.addItems(["Option A", "Option B", "Option C"]) self.combo.currentTextChanged.connect(self.update_combo_label) The Role of Widgets in PyQt6 self

import sys from PyQt6.QtWidgets import (QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton, QStatusBar)

: A dropdown menu.

from PyQt6.QtWidgets import * from PyQt6.QtCore import Qt Titles, instructions, or static status text

Example:

def main(): app = QApplication(sys.argv) line_edit = QLineEdit() line_edit.show() sys.exit(app.exec())

Most applications rely on a standard set of widgets provided by the QtWidgets module: Widget Name Description Key Use Case A non-interactive widget for displaying text or images. Titles, instructions, or static status text. QPushButton A command button that triggers an action when clicked. "Submit" buttons, "Close" buttons. QLineEdit A single-line text editor. Usernames, search bars, or numerical inputs. QTextEdit A multi-line text editor supporting rich text. Notes, descriptions, or logs. QCheckBox An option button that can be toggled on or off. Settings or multi-select filters. QComboBox A drop-down list of options. Language selection or category picking. Layout Management