As a PyQt developer with experience in creating desktop applications, I have worked extensively with various widgets and configurations. I am excited to share my knowledge about the fundamental widgets in PyQt6 that form the building blocks of any modern desktop application. Let us get into the topic of PyQt6 widgets and explore how can we use them.
What is PyQt6?
PyQt6 is the latest version of PyQt, a set of Python bindings for The Qt Company’s Qt application framework. Released in 2021, PyQt6 brings modern GUI capabilities to Python developers, allowing us to create cross-platform applications that run seamlessly on Windows, macOS, and Linux.
Before getting into the widgets, let’s make sure we have PyQt6 installed:
# Install PyQt6 using pip
pip install PyQt6
Now, let’s explore the essential widgets that will become your toolkit for application development.
Read Create a Basic Window in PyQt6
1. QLabel: The Foundation of Text Display
QLabel is one of the simplest yet most frequently used widgets in PyQt6. I use it whenever I need to display text or images that users don’t need to interact with.
Basic Implementation of QLabel
import sys
from PyQt6.QtWidgets import QApplication, QLabel, QWidget
from PyQt6.QtCore import Qt
class SimpleWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("My First PyQt6 Application")
self.setGeometry(100, 100, 400, 200)
# Creating a simple label
self.label = QLabel("Welcome to PyQt6!", self)
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label.setStyleSheet("font-size: 24px; color: #0066cc;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = SimpleWindow()
window.show()
sys.exit(app.exec())
You can see the output in the screenshot below.

Key Methods for QLabel
| Method | Description |
|---|---|
| setText() | Changes the text displayed in the label |
| setPixmap() | Displays an image instead of text |
| setAlignment() | Controls how content is aligned |
| setWordWrap() | Enables/disables text wrapping |
| linkActivated | Signal emitted when a user clicks a hyperlink |
Check out QComboBox Widget in PyQt6
2. QPushButton: Interactive User Control
Buttons are essential for user interaction. In my applications, I use QPushButton to initiate actions, submit forms, or navigate between different sections of the application.
Create Responsive Buttons
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
import sys
class ButtonExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Button Example")
self.setGeometry(100, 100, 300, 200)
# Create a layout
layout = QVBoxLayout()
# Create a button
self.button = QPushButton("Click Me!", self)
self.button.clicked.connect(self.on_button_click)
# Add button to layout
layout.addWidget(self.button)
self.setLayout(layout)
def on_button_click(self):
self.button.setText("Button Clicked!")
self.button.setStyleSheet("background-color: #4CAF50; color: white;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = ButtonExample()
window.show()
sys.exit(app.exec())
You can see the output in the screenshot below.

QPushButton Features
- Checkable Buttons: Create toggle buttons with
setCheckable(True) - Default and Auto-Default: Set a button as the default action with
setDefault(True) - Icons: Add visual elements with
setIcon() - Shortcuts: Assign keyboard shortcuts with
setShortcut()
Read Create a Random Number Generator with QLCDNumber in PyQt6
3. QLineEdit: User Input Made Simple
For collecting user input, QLineEdit is my go-to widget. Whether I’m building a login screen for a healthcare application in Boston or a search feature for a retail system in Chicago, QLineEdit provides a seamless text input experience.
Basic Implementation
from PyQt6.QtWidgets import QApplication, QWidget, QLineEdit, QVBoxLayout, QLabel
import sys
class InputExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Input Example")
self.setGeometry(100, 100, 300, 150)
# Create layout
layout = QVBoxLayout()
# Create label and input
self.label = QLabel("Enter your name:")
self.input = QLineEdit()
self.input.setPlaceholderText("John Smith")
self.input.textChanged.connect(self.text_changed)
# Add widgets to layout
layout.addWidget(self.label)
layout.addWidget(self.input)
self.setLayout(layout)
def text_changed(self, text):
if text:
self.label.setText(f"Hello, {text}!")
else:
self.label.setText("Enter your name:")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = InputExample()
window.show()
sys.exit(app.exec())
You can see the output in the screenshot below.

QLineEdit Methods and Properties
| Method/Property | Purpose |
|---|---|
| setText() | Set the text content programmatically |
| text() | Get the current text content |
| setEchoMode() | Control how text is displayed (useful for passwords) |
| setMaxLength() | Limit the number of characters |
| setReadOnly() | Make the field non-editable |
| setPlaceholderText() | Add helper text when field is empty |
Check out Build a Simple Digital Clock with QLCDNumber in PyQt6
4. QCheckBox: Boolean Input Options
QCheckBox widgets are perfect for yes/no or true/false options in your applications. I frequently use them in settings screens or preference dialogs.
QCheckBox Implementation
from PyQt6.QtWidgets import QApplication, QWidget, QCheckBox, QVBoxLayout, QLabel
import sys
class CheckboxExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Checkbox Example")
self.setGeometry(100, 100, 300, 150)
# Create layout
layout = QVBoxLayout()
# Create checkbox
self.checkbox = QCheckBox("Subscribe to newsletter", self)
self.checkbox.stateChanged.connect(self.state_changed)
# Create label for status
self.status = QLabel("Not subscribed")
# Add widgets to layout
layout.addWidget(self.checkbox)
layout.addWidget(self.status)
self.setLayout(layout)
def state_changed(self, state):
if state:
self.status.setText("You are now subscribed!")
self.status.setStyleSheet("color: green;")
else:
self.status.setText("Not subscribed")
self.status.setStyleSheet("color: red;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CheckboxExample()
window.show()
sys.exit(app.exec())
You can see the output in the screenshot below.

5. QComboBox: Dropdown Selection Made Easy
QComboBox (dropdown) is an efficient user interface element for selecting one option from many. I implement it in almost all of my applications.
QComboBox Example
from PyQt6.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout, QLabel
import sys
class ComboBoxExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("State Selector")
self.setGeometry(100, 100, 350, 200)
# Create layout
layout = QVBoxLayout()
# Create label
self.label = QLabel("Select your state:")
# Create combo box
self.combo = QComboBox()
self.combo.addItems(["California", "Texas", "New York", "Florida", "Illinois"])
self.combo.currentTextChanged.connect(self.selection_changed)
# Result label
self.result = QLabel("")
# Add widgets to layout
layout.addWidget(self.label)
layout.addWidget(self.combo)
layout.addWidget(self.result)
self.setLayout(layout)
def selection_changed(self, text):
state_info = {
"California": "Sacramento is the capital",
"Texas": "Austin is the capital",
"New York": "Albany is the capital",
"Florida": "Tallahassee is the capital",
"Illinois": "Springfield is the capital"
}
self.result.setText(state_info.get(text, ""))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = ComboBoxExample()
window.show()
sys.exit(app.exec())
Key QComboBox Methods
- addItem/addItems: Add one or multiple items to the dropdown
- currentText/currentIndex: Get the selected item as text or its position
- setEditable: Allow users to enter custom values
- clear: Remove all items from the dropdown
- count: Get the number of items in the dropdown
Check out QSpinBox Widget in PyQt6
6. QRadioButton: Exclusive Selection
When users need to select exactly one option from a group, QRadioButton is my preferred widget. It’s particularly useful for settings where options are mutually exclusive.
QRadioButton Implementation
from PyQt6.QtWidgets import (QApplication, QWidget, QRadioButton,
QVBoxLayout, QLabel, QButtonGroup)
import sys
class RadioButtonExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Payment Method")
self.setGeometry(100, 100, 300, 200)
# Create layout
layout = QVBoxLayout()
# Create label
self.label = QLabel("Select your payment method:")
layout.addWidget(self.label)
# Create button group for exclusive selection
self.button_group = QButtonGroup(self)
# Create radio buttons
payment_methods = ["Credit Card", "PayPal", "Bank Transfer", "Apple Pay"]
self.radio_buttons = []
for i, method in enumerate(payment_methods):
radio = QRadioButton(method)
self.radio_buttons.append(radio)
layout.addWidget(radio)
self.button_group.addButton(radio, i)
# Default selection
self.radio_buttons[0].setChecked(True)
# Connect signal
self.button_group.buttonClicked.connect(self.on_button_clicked)
# Selection result
self.result = QLabel("Selected: Credit Card")
layout.addWidget(self.result)
# Set layout
self.setLayout(layout)
def on_button_clicked(self, button):
self.result.setText(f"Selected: {button.text()}")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = RadioButtonExample()
window.show()
sys.exit(app.exec())
7. QSlider: Visual Range Selection
For selecting a value from a continuous range, QSlider provides an intuitive interface that I implement in applications requiring numerical input within boundaries.
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QSlider
from PyQt6.QtCore import Qt
class SliderExample(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QSlider Example")
self.setGeometry(100, 100, 300, 150)
# Layout
layout = QVBoxLayout()
# Label to display the value
self.label = QLabel("Selected Value: 0", self)
# QSlider
self.slider = QSlider(Qt.Orientat