from PyQt5.QtWidgets import QRadioButton, QButtonGroup, QVBoxLayout button_group = QButtonGroup() button1 = QRadioButton("Button 1") button2 = QRadioButton("Button 2") button3 = QRadioButton("Button 3") button_group.addButton(button1) button_group.addButton(button2) button_group.addButton(button3) layout = QVBoxLayout() layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3)
from PyQt5.QtWidgets import QPushButton, QButtonGroup, QVBoxLayout button_group = QButtonGroup() button1 = QPushButton("Button 1") button2 = QPushButton("Button 2") button3 = QPushButton("Button 3") button_group.addButton(button1, 1) button_group.addButton(button2, 2) button_group.addButton(button3, 3) layout = QVBoxLayout() layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) checked_button = button_group.checkedButton() if checked_button is not None: print("Button {} is checked!".format(button_group.id(checked_button)))This example shows how to retrieve the checked button from a group using checkedButton(). The id of the checked button can be retrieved using id(). This package belongs to the PyQt5 library.