WIDGETS
Widgets are the controls your users see and touch. This guide introduces the ones you will reach for in almost every PyQt app, with a short snippet for each so you can drop them straight in.
Labels and buttons
These two are the bread and butter of any screen. A label shows text. A button triggers an action when clicked.
from PyQt6.QtWidgets import QLabel, QPushButton
title = QLabel("Welcome")
save = QPushButton("Save")Connect the button's clicked signal to a function and it springs to life. See our signals guide for that step.
Text inputs
Use QLineEdit for a single line, and QTextEdit for multi-line text:
from PyQt6.QtWidgets import QLineEdit, QTextEdit
name = QLineEdit(); name.setPlaceholderText("Your name")
notes = QTextEdit()Placeholder text is a small touch that makes forms far friendlier.
Checkboxes and combos
For yes/no options use QCheckBox. For picking one item from a list use QComboBox:
from PyQt6.QtWidgets import QCheckBox, QComboBox
agree = QCheckBox("I agree")
pick = QComboBox(); pick.addItems(["Small", "Medium", "Large"])Numbers and sliders
Use QSpinBox for whole numbers and QSlider for a dragging control:
from PyQt6.QtWidgets import QSpinBox, QSlider from PyQt6.QtCore import Qt count = QSpinBox(); count.setRange(0, 100) vol = QSlider(Qt.Orientation.Horizontal)
Both emit a signal when their value changes, so you can react live.
Showing data in tables
QTableWidget shows rows and columns of data. It is ideal for records, results and simple spreadsheets:
from PyQt6.QtWidgets import QTableWidget, QTableWidgetItem
t = QTableWidget(2, 2)
t.setItem(0, 0, QTableWidgetItem("Alice"))
t.setItem(0, 1, QTableWidgetItem("30"))Containers and beyond
Beyond the basics there are hundreds more. Tabs group screens with QTabWidget. Trees show nested data with QTreeWidget. Dialogs pop up messages and file pickers. Progress bars show how long is left. You arrange any of them with layouts.
Dialogs and message boxes
Not everything belongs in the main window. For quick questions and alerts, PyQt has ready-made dialogs. A message box shows a warning or asks yes or no. File dialogs let the user open or save a file with the native picker.
These save huge amounts of work. Instead of building a custom pop-up, you call one line and get a polished, native dialog that users already know how to use.
Styling widgets
Every widget can be restyled with a Qt style sheet. The rules look like CSS: you target a widget type or name and set colours, borders, padding and fonts. You can theme the whole app or tweak a single control.
Keep your styles in one place so the look stays consistent. A small, shared style sheet gives even a simple app a finished, professional feel.
Picking the right widget
With so many widgets, the trick is matching the control to the task. Use a combo box for one choice from many, radio buttons for a small visible set, and check boxes for independent on/off options.
For data, a list widget suits a simple column, while a table widget handles rows and columns. Choosing the natural control makes your app easier to use and easier to build.
How widgets are grouped
With over a thousand classes, it helps to see the groups. There are display widgets like labels and images. Input widgets like text boxes, spin boxes and sliders. Button widgets for actions and choices. Container widgets like tabs and group boxes that hold other widgets.
Then there are item views for data — lists, tables and trees — and top-level windows and dialogs. Almost everything you need fits into one of these families, which makes finding the right class much easier.
When you need something specific, think about which family it belongs to first. That narrows the search from a thousand classes to a handful, and the right one usually jumps out.
Widgets and layouts together
Widgets rarely work alone. You place them inside layouts, which position and resize them for you. A label and an input go into a form layout. A row of buttons goes into a horizontal layout. The whole screen sits in a vertical layout.
This pairing is the heart of building a screen. Pick the widgets that match the task, then arrange them with the layout that fits the shape. The two skills together let you build almost any interface.
Practise by recreating a screen you use often, such as a login form or a settings page. You will quickly see how a few widgets and layouts combine into something familiar and polished.
Key takeaways
Widgets are the controls your users see and touch, and PyQt has one for almost every need. Labels and buttons, text inputs, checkboxes and combos, spin boxes and sliders, tables and trees, plus ready-made dialogs for alerts and file pickers.
The skill is matching the control to the task, then arranging it with a layout and wiring its signal to your code. Pick the natural widget — a combo for one choice, check boxes for independent options, a table for rows and columns — and the app feels right.
Style everything with a shared Qt style sheet to keep a consistent, professional look. With the right widgets, sensible layouts and a little styling, you can build almost any interface you can picture.
FAQs
How many widgets does PyQt have?
Over a thousand classes in total, covering every common need and many rare ones.
How do I react when a widget changes?
Connect its signal to a function. Most widgets emit a signal on change or click.
Can I style widgets?
Yes. Qt stylesheets use CSS-like rules to change colours, fonts and borders.
Which widget is best for a list of items?
Use QListWidget for a simple list, or QTableWidget when you need columns.
Conclusion
With labels, buttons, inputs, choices, numbers and tables, you can build almost any screen. Drop them into a layout, connect their signals, and you have a working app. Try combining a few in our first example to see them in action.
Ready to start? Download PyQt or run pip install PyQt6.