Вам надо обратить внимание на ООП. Если вы хотите получить доступ к объектам в других методах класса и т.п., эти объекты должны быть экземплярами класса.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class ClassesPage1(QtWidgets.QWizardPage):
def __init__(self, parent=None): # +++ parent=None
super(ClassesPage1, self).__init__()
self.setTitle("...")
self.setSubTitle("...")
self.label_1 = QtWidgets.QLabel('label_1')
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.layout = QtWidgets.QVBoxLayout()
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_1)
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 # +++ self.a
for checkBox in self.listCheckBox:
if checkBox.isChecked():
self.a += 1 # +++ self.a
self.mean = self.a / 4 # +++ self.mean
''' ??????????????????????????????????????????????????????????????????????????
if self.mean == 1:
self.label_1.setText('\n\n\n\n\n\n\n\n\n\n\n Среднее значение: 1')
elif self.mean == 0:
self.label_1.setText('\n\n\n\n\n\n\n\n\n\n\n Среднее значение: 0')
else:
self.label_1.setText('\n\n\n\n\n\n\n\n\n\n\n Среднее значение: ' + str(self.mean))
'''
self.label_1.setText(f'Среднее значение: {self.mean}') # +++
self.parent._print() # +++
def nextId(self):
return Wizard.class4
class Parametrs:
def __init__(self):
super().__init__()
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}')
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Parametrs()
sys.exit(app.exec_())
