from PyQt5.QtWidgets import QWidget, QRadioButton, QVBoxLayout, QApplication class Window(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): layout = QVBoxLayout() self.button1 = QRadioButton("Option 1") self.button2 = QRadioButton("Option 2") self.button3 = QRadioButton("Option 3") layout.addWidget(self.button1) layout.addWidget(self.button2) layout.addWidget(self.button3) self.setLayout(layout) app = QApplication([]) window = Window() window.show() app.exec_()
def selectedButton(self): if self.button1.isChecked(): print("Option 1 selected") elif self.button2.isChecked(): print("Option 2 selected") elif self.button3.isChecked(): print("Option 3 selected")In this example, we define a function that checks which QRadioButton is currently selected and prints out its label. This function could be called on a button press or in response to some other event.