
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QRadioButton Widget
A QRadioButton class object presents a selectable button with a text label. It is commonly used when the user need to choose one option from a list of options. This widget is represented by a small circular button that can be toggled on (checked) or off (unchecked). This class is derived from QAbstractButton class.

QRadioButton Auto-Exclusiove Behaviour
Radio buttons are autoexclusive by default. Hence, only one of the radio buttons in the parent window can be selected at a time. If one is selected, previously selected button is automatically deselected. Radio buttons can also be put in a QGroupBox or QButtonGroup to create more than one selectable fields on the parent window.
Signaling
Whenever a QRadioButton is toggled, it emits the toggled() signal. This signal can be connected to trigger actions in response to changes in the button's state. We can also use the isChecked() method to determine if a particular button is currently selected.
Text and Icons
Similar to other button-like widgets such as QPushButton, QRadioButton can display both text and optional icons. The text content can be set either during initialization or dynamically using the setText() method. Shortcut keys can also be specified within the text for accessibility purposes.
Methods of QRadioButton Class
The following listed methods of QRadioButton class are most commonly used.
Sr.No. | Methods & Description |
---|---|
1 |
setChecked() Changes the state of radio button |
2 |
setText() Sets the label associated with the button |
3 |
text() Retrieves the caption of button |
4 |
isChecked() Checks if the button is selected |
Default signal associated with QRadioButton object is toggled(), although other signals inherited from QAbstractButton class can also be implemented.
Example
Here two mutually exclusive radio buttons are constructed on a top level window.
Default state of b1 is set to checked by the statement −
Self.b1.setChecked(True)
The toggled() signal of both the buttons is connected to btnstate() function. Use of lambda allows the source of signal to be passed to the function as an argument.
self.b1.toggled.connect(lambda:self.btnstate(self.b1)) self.b2.toggled.connect(lambda:self.btnstate(self.b2))
The btnstate() function checks state of button emitting toggled() signal.
import sys from PyQt6.QtCore import * from PyQt6.QtGui import * from PyQt6.QtWidgets import QWidget,QApplication, QRadioButton,QHBoxLayout class Radiodemo(QWidget): def __init__(self, parent = None): super(Radiodemo, self).__init__(parent) layout = QHBoxLayout() self.b1 = QRadioButton("Button1") self.b1.setChecked(True) self.b1.toggled.connect(lambda:self.btnstate(self.b1)) layout.addWidget(self.b1) self.b2 = QRadioButton("Button2") self.b2.toggled.connect(lambda:self.btnstate(self.b2)) layout.addWidget(self.b2) self.setLayout(layout) self.setWindowTitle("RadioButton demo") def btnstate(self,b): if b.text() == "Button1": if b.isChecked() == True: print (b.text()+" is selected") else: print (b.text()+" is deselected") if b.text() == "Button2": if b.isChecked() == True: print (b.text()+" is selected") else: print (b.text()+" is deselected") def main(): app = QApplication(sys.argv) ex = Radiodemo() ex.show() sys.exit(app.exec()) if __name__ == '__main__': main()
Output
The above code produces the following output −

Button1 is deselected Button2 is selected Button2 is deselected Button1 is selected
Example: Grouping Radio button
In the below example, we will create a group radio button using QButtonGroup to enforce exclusive selection within each group.
import sys from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QRadioButton, QButtonGroup class RadioButtonsGroupExample(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): layout = QVBoxLayout() self.group1 = QButtonGroup() self.group2 = QButtonGroup() self.radio_button1 = QRadioButton("Option 1") self.radio_button2 = QRadioButton("Option 2") self.radio_button3 = QRadioButton("Option 3") self.radio_button4 = QRadioButton("Option 4") layout.addWidget(self.radio_button1) layout.addWidget(self.radio_button2) layout.addWidget(self.radio_button3) layout.addWidget(self.radio_button4) self.group1.addButton(self.radio_button1) self.group1.addButton(self.radio_button2) self.group2.addButton(self.radio_button3) self.group2.addButton(self.radio_button4) self.setLayout(layout) if __name__ == '__main__': app = QApplication(sys.argv) ex = RadioButtonsGroupExample() ex.show() sys.exit(app.exec())
Output
The above code produces the following output −
