import sys from PyQt5.QtWidgets import QApplication, QWidget, QRadioButton class MyWidget(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(100, 100, 300, 300) self.radioButton = QRadioButton('Option 1', self) self.radioButton.setGeometry(50, 50, 100, 20) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QRadioButton, QGridLayout class MyWidget(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(100, 100, 300, 300) grid = QGridLayout() radioButton1 = QRadioButton('Option 1', self) radioButton2 = QRadioButton('Option 2', self) radioButton3 = QRadioButton('Option 3', self) radioButton1.setGeometry(50, 50, 100, 20) radioButton2.setGeometry(50, 80, 100, 20) radioButton3.setGeometry(50, 110, 100, 20) grid.addWidget(radioButton1, 0, 0) grid.addWidget(radioButton2, 1, 0) grid.addWidget(radioButton3, 2, 0) self.setLayout(grid) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec_())In this example, a group of three QRadioButtons are created and are positioned at different vertical distances from each other using the setGeometry method. They are then added to a QGridLayout, which arranges them in a grid format. Package/library: PyQt5