from PyQt5.QtWidgets import QApplication, QRadioButton, QVBoxLayout, QWidget app = QApplication([]) main_window = QWidget() layout = QVBoxLayout() button_1 = QRadioButton('Option 1') layout.addWidget(button_1) button_2 = QRadioButton('Option 2') layout.addWidget(button_2) main_window.setLayout(layout) main_window.show() # Check if button 1 is selected if button_1.isChecked(): print('Button 1 is selected') else: print('Button 2 is selected')
from PyQt5.QtWidgets import QApplication, QRadioButton, QVBoxLayout, QWidget app = QApplication([]) main_window = QWidget() layout = QVBoxLayout() button_1 = QRadioButton('Option 1') layout.addWidget(button_1) button_2 = QRadioButton('Option 2') layout.addWidget(button_2) # Set button 1 as the default checked button button_1.setChecked(True) main_window.setLayout(layout) main_window.show()In this example, we set button_1 as the default checked radio button by calling setChecked(True) on it. When the window is shown, button_1 will be the default selected option. Overall, these examples show how to use the isChecked() method in PyQt5.QtWidgets QRadioButton to check if a radio button is selected, and how to set the default checked radio button.