from PyQt5.QtWidgets import QApplication, QRadioButton, QWidget, QVBoxLayout app = QApplication([]) window = QWidget() layout = QVBoxLayout() radio1 = QRadioButton("Option 1") layout.addWidget(radio1) radio2 = QRadioButton("Option 2") layout.addWidget(radio2) radio3 = QRadioButton("Option 3") layout.addWidget(radio3) #disabling option 2 radio2.setDisabled(True) window.setLayout(layout) window.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QRadioButton, QWidget, QVBoxLayout app = QApplication([]) window = QWidget() layout = QVBoxLayout() radio4 = QRadioButton("Large Font") layout.addWidget(radio4) radio5 = QRadioButton("Small Font") layout.addWidget(radio5) def on_font_size_changed(): if radio4.isChecked(): print("Large font selected") elif radio5.isChecked(): print("Small font selected") #connecting the radio buttons with a function radio4.toggled.connect(on_font_size_changed) radio5.toggled.connect(on_font_size_changed) window.setLayout(layout) window.show() app.exec_()In this example, two radio buttons are created with labels "Large Font" and "Small Font". A function on_font_size_changed is defined and connected to the two radio buttons using toggled signal. When one of the radio buttons is selected, the function will print out which option was selected. Package library: PyQt5.