Unsolved Incorrectly passed from class to class
-
The value is incorrectly passed from the ClassesPage1 class to the Parametrs class. The incorrectness is that:
- The window closes when I click on the select answer button
- In the second window (which should not be) everything is counted and displayed correctly. I commented out this line of code.
from PyQt5 import QtWidgets, QtCore, QtGui from PyQt5.QtCore import Qt from PyQt5.QtGui import * import sys class ClassesPage1(QtWidgets.QWizardPage): def __init__(self, parent=None, mean=None, *args, **kwargs): super(ClassesPage1, self).__init__(parent=None, *args, **kwargs) self.label_2 = QtWidgets.QLabel("lbl1...", self) self.label_2.setAlignment(Qt.AlignCenter) self.label_3 = QtWidgets.QLabel("lbl2...", self) self.label_3.setAlignment(Qt.AlignLeft) self.checkBox_1 = QtWidgets.QCheckBox('cb1...') self.checkBox_2 = QtWidgets.QCheckBox('cb2...') self.checkBox_3 = QtWidgets.QCheckBox('cb3...') self.checkBox_4 = QtWidgets.QCheckBox('cb4...') self.label_5 = QtWidgets.QLabel('lbl3...') self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.label_2) self.layout.addWidget(self.label_3) self.layout.addWidget(self.checkBox_1) self.layout.addWidget(self.checkBox_2) self.layout.addWidget(self.checkBox_3) self.layout.addWidget(self.checkBox_4) self.layout.addWidget(self.label_5) self.setLayout(self.layout) self.checkBox_1.stateChanged.connect(self.check) self.checkBox_2.stateChanged.connect(self.check) self.checkBox_3.stateChanged.connect(self.check) self.checkBox_4.stateChanged.connect(self.check) self.listCheckBox = [self.checkBox_1, self.checkBox_2, self.checkBox_3, self.checkBox_4] self.a = 0 self.parent = parent self.mean = 0 def check(self): self.a = 0 for checkBox in self.listCheckBox: if checkBox.isChecked(): self.a += 1 self.mean = self.a / 4 self.label_5.setText(f'Avarage: {self.mean}') self.parent._print() def nextId(self): return Wizard.class4 class Parametrs(QtWidgets.QWizardPage): def __init__(self, *args, **kwargs): super(Parametrs, self).__init__(*args, **kwargs) self.par = ClassesPage1(self) #self.par.show() print(f'__init__: par.mean = {self.par.mean}') def _print(self): print(f'par.mean = {self.par.mean:.2f}') def nextId(self): return Wizard.classParametrs1 if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) wizard = Wizard() wizard.show() sys.exit(app.exec_())
-
@sashup said in Incorrectly passed from class to class:
answer button
Where is this button? Which windows closes?
Please format your code properly. -
@jsulm It is checkBox1, checkBox2, checkBox3 or checkBox4
-
@sashup In Parametrs
... self.par = ClassesPage1(self) #self.par.show() print(f'__init__: par.mean = {self.par.mean}') ...
-
@sashup Do you mean the window closes when check() is called, or what? Did you use debugger to see what happens?
-
@jsulm It looks like