from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QVBoxLayout()
self.setLayout(layout)
self.label = QLabel("Сумма = 0")
layout.addWidget(self.label)
self.sum = 0
self.gb_list = {}
for i in range(1, 10):
gb_layout = QHBoxLayout()
gb_widget = QWidget()
gb_widget.setLayout(gb_layout)
gb = QButtonGroup(gb_widget)
for j in range(1, 10):
radiobutton = QRadioButton()
radiobutton.setChecked(False)
radiobutton.number = "{}".format(i)
radiobutton.value = "{}".format(j)
radiobutton.toggled.connect(self.onClicked)
gb.addButton(radiobutton)
gb_layout.addWidget(radiobutton)
layout.addWidget(gb_widget)
def onClicked(self):
radioButton = self.sender()
if radioButton.isChecked():
self.gb_list[radioButton.number] = int(radioButton.value)
self.label.setText("Сумма = {}".format(sum(self.gb_list.values())))
app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())