@idwdino

Как сложить текстовые значения radiobutton?

У меня есть 70~ радиобатонов, каждые 6 вставлены в групп боксы, надо как эти значения радиобатонов перемножить, никак не могу найти как 626031fd69f7c177649261.jpeg
self.Button_result.setText(_translate("MainWindow", "PushButton"))
        self.radioButton_4.setText(_translate("MainWindow", "2"))
        self.radioButton_3.setText(_translate("MainWindow", "3"))
        self.radioButton_2.setText(_translate("MainWindow", "4"))
        self.radioButton_6.setText(_translate("MainWindow", "5"))
        self.radioButton_5.setText(_translate("MainWindow", "6"))
        self.radioButton.setText(_translate("MainWindow", "7"))
        self.radioButton_7.setText(_translate("MainWindow", "8"))
        self.radioButton_8.setText(_translate("MainWindow", "0"))
        self.radioButton_9.setText(_translate("MainWindow", "0"))
        self.radioButton_10.setText(_translate("MainWindow", "0"))
        self.radioButton_11.setText(_translate("MainWindow", "0"))
        self.radioButton_12.setText(_translate("MainWindow", "0"))
        self.radioButton_13.setText(_translate("MainWindow", "0"))
        self.radioButton_14.setText(_translate("MainWindow", "0"))
        self.radioButton_15.setText(_translate("MainWindow", "0"))
        self.radioButton_16.setText(_translate("MainWindow", "0"))
        self.radioButton_17.setText(_translate("MainWindow", "0"))
        self.radioButton_18.setText(_translate("MainWindow", "0"))
        self.radioButton_19.setText(_translate("MainWindow", "0"))
        self.radioButton_20.setText(_translate("MainWindow", "0"))
        self.radioButton_21.setText(_translate("MainWindow", "0"))
        self.radioButton_22.setText(_translate("MainWindow", "0"))
        self.radioButton_23.setText(_translate("MainWindow", "0"))
        self.radioButton_24.setText(_translate("MainWindow", "0"))
        self.radioButton_31.setText(_translate("MainWindow", "0"))
        self.radioButton_32.setText(_translate("MainWindow", "0"))
        self.radioButton_33.setText(_translate("MainWindow", "0"))
        self.radioButton_34.setText(_translate("MainWindow", "0"))
        self.radioButton_35.setText(_translate("MainWindow", "0"))
        self.radioButton_36.setText(_translate("MainWindow", "0"))
        self.radioButton_37.setText(_translate("MainWindow", "0"))
        self.radioButton_38.setText(_translate("MainWindow", "0"))
        self.radioButton_39.setText(_translate("MainWindow", "0"))
        self.radioButton_40.setText(_translate("MainWindow", "0"))
        self.radioButton_41.setText(_translate("MainWindow", "0"))
        self.radioButton_42.setText(_translate("MainWindow", "0"))
        self.radioButton_43.setText(_translate("MainWindow", "0"))
        self.radioButton_44.setText(_translate("MainWindow", "0"))
        self.radioButton_45.setText(_translate("MainWindow", "0"))
        self.radioButton_46.setText(_translate("MainWindow", "0"))
        self.radioButton_47.setText(_translate("MainWindow", "0"))
        self.radioButton_48.setText(_translate("MainWindow", "0"))
        self.radioButton_49.setText(_translate("MainWindow", "0"))
        self.radioButton_50.setText(_translate("MainWindow", "0"))
        self.radioButton_51.setText(_translate("MainWindow", "0"))
        self.radioButton_52.setText(_translate("MainWindow", "0"))
        self.radioButton_53.setText(_translate("MainWindow", "0"))
        self.radioButton_54.setText(_translate("MainWindow", "0"))
        self.radioButton_55.setText(_translate("MainWindow", "0"))
        self.radioButton_56.setText(_translate("MainWindow", "0"))
        self.radioButton_57.setText(_translate("MainWindow", "0"))
        self.radioButton_58.setText(_translate("MainWindow", "0"))
        self.radioButton_59.setText(_translate("MainWindow", "0"))
        self.radioButton_60.setText(_translate("MainWindow", "0"))
        self.radioButton_61.setText(_translate("MainWindow", "0"))
        self.radioButton_62.setText(_translate("MainWindow", "0"))
        self.radioButton_63.setText(_translate("MainWindow", "0"))
        self.radioButton_64.setText(_translate("MainWindow", "0"))
        self.radioButton_65.setText(_translate("MainWindow", "0"))
        self.radioButton_66.setText(_translate("MainWindow", "0"))
        self.radioButton_67.setText(_translate("MainWindow", "0"))
        self.radioButton_68.setText(_translate("MainWindow", "0"))
        self.radioButton_69.setText(_translate("MainWindow", "0"))
        self.radioButton_70.setText(_translate("MainWindow", "0"))
        self.radioButton_71.setText(_translate("MainWindow", "0"))
        self.radioButton_72.setText(_translate("MainWindow", "0"))
        self.radioButton_73.setText(_translate("MainWindow", "0"))
        self.radioButton_74.setText(_translate("MainWindow", "0"))
        self.radioButton_75.setText(_translate("MainWindow", "0"))
        self.radioButton_76.setText(_translate("MainWindow", "0"))
        self.radioButton_77.setText(_translate("MainWindow", "0"))
        self.radioButton_78.setText(_translate("MainWindow", "0"))
        self.radioButton_79.setText(_translate("MainWindow", "0"))
        self.radioButton_80.setText(_translate("MainWindow", "0"))
        self.radioButton_81.setText(_translate("MainWindow", "0"))
        self.radioButton_82.setText(_translate("MainWindow", "0"))
        self.radioButton_83.setText(_translate("MainWindow", "0"))
        self.radioButton_84.setText(_translate("MainWindow", "0"))
        self.radioButton_85.setText(_translate("MainWindow", "0"))
        self.radioButton_86.setText(_translate("MainWindow", "0"))
        self.radioButton_87.setText(_translate("MainWindow", "0"))
        self.radioButton_88.setText(_translate("MainWindow", "0"))
        self.radioButton_89.setText(_translate("MainWindow", "0"))
        self.radioButton_90.setText(_translate("MainWindow", "0"))
        self.radioButton_91.setText(_translate("MainWindow", "0"))
        self.radioButton_92.setText(_translate("MainWindow", "0"))
        self.radioButton_93.setText(_translate("MainWindow", "0"))
        self.radioButton_94.setText(_translate("MainWindow", "0"))
        self.radioButton_95.setText(_translate("MainWindow", "0"))
        self.radioButton_96.setText(_translate("MainWindow", "0"))
  
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec())
  • Вопрос задан
  • 126 просмотров
Решения вопроса 1
seven5674
@seven5674
Старый я уже что бы что-то в себе менять
Вот пример для суммы
Как перемножить думаю что сами догадаетесь

Код

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_())



6260e8f1e1e71034253044.png
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы