Помогите пожалуйста, как передать переменную из одного класса в другой. Вот кусок кода, есть коментарие!
class MyStart(QMainWindow, Ui_Dialog):
def __init__(self, p=None, pp=None):
super().__init__()
self.p = p
self.pp = pp
self.setupUi(self)
self.pushButton_2.clicked.connect(self.go)
self.pushButton.clicked.connect(self.gou)
def go(self):
if self.p is not None:
self.d = self.p(self.pp)
self.d.show()
self.close()
def gou(self):
name = self.lineEdit.text()
passw = self.lineEdit_2.text()
conn = sqlite3.connect("dnevnik.db")
cursor = conn.cursor()
cursor.execute(f'SELECT * FROM users WHERE fname="{name}";')
self.value = cursor.fetchall()
print(self.value)
if self.value != [] and self.value[0][1] == int(passw):
print('Успешная авторизация!')
self.d = GOGO(MyStart, self.value, self.p) #передаю эту переменную
self.d.show()
self.close()
else:
print('Проверьте правильность ввода данных!')
cursor.close()
class Dialog(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(526, 532)
self.line = QtWidgets.QFrame(MainWindow)
self.line.setGeometry(QtCore.QRect(-10, 510, 541, 21))
self.line.setStyleSheet("background-color: rgb(255, 170, 255);")
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.line_3 = QtWidgets.QFrame(MainWindow)
self.line_3.setGeometry(QtCore.QRect(0, -10, 20, 551))
self.line_3.setStyleSheet("background-color: rgb(85, 255, 127);")
self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_3.setObjectName("line_3")
self.line_4 = QtWidgets.QFrame(MainWindow)
self.line_4.setGeometry(QtCore.QRect(0, 0, 531, 21))
self.line_4.setStyleSheet("background-color: rgb(85, 170, 255);")
self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_4.setObjectName("line_4")
self.label = QtWidgets.QLabel(MainWindow)
self.label.setGeometry(QtCore.QRect(30, 30, 61, 21))
self.label.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(MainWindow)
self.label_2.setGeometry(QtCore.QRect(30, 80, 61, 21))
self.label_2.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(MainWindow)
self.label_3.setGeometry(QtCore.QRect(30, 120, 61, 21))
self.label_3.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(MainWindow)
self.label_4.setGeometry(QtCore.QRect(30, 160, 61, 21))
self.label_4.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(MainWindow)
self.label_5.setGeometry(QtCore.QRect(30, 200, 61, 21))
self.label_5.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(MainWindow)
self.label_6.setGeometry(QtCore.QRect(30, 240, 81, 21))
self.label_6.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(MainWindow)
self.label_7.setGeometry(QtCore.QRect(30, 280, 71, 21))
self.label_7.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(MainWindow)
self.label_8.setGeometry(QtCore.QRect(30, 320, 61, 21))
self.label_8.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(MainWindow)
self.label_9.setGeometry(QtCore.QRect(30, 360, 71, 21))
self.label_9.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(MainWindow)
self.label_10.setGeometry(QtCore.QRect(30, 400, 91, 21))
self.label_10.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(MainWindow)
self.label_11.setGeometry(QtCore.QRect(30, 440, 61, 21))
self.label_11.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(MainWindow)
self.label_12.setGeometry(QtCore.QRect(30, 480, 91, 21))
self.label_12.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_12.setObjectName("label_12")
self.line_5 = QtWidgets.QFrame(MainWindow)
self.line_5.setGeometry(QtCore.QRect(420, 20, 5, 491))
self.line_5.setStyleSheet("background-color: rgb(0, 0, 0);")
self.line_5.setFrameShape(QtWidgets.QFrame.VLine)
self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_5.setObjectName("line_5")
self.label_13 = QtWidgets.QLabel(MainWindow)
self.label_13.setGeometry(QtCore.QRect(430, 30, 61, 21))
self.label_13.setStyleSheet("font: 75 10pt \"MS Shell Dlg 2\";")
self.label_13.setObjectName("label_13")
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Dialog"))
self.label.setText(_translate("MainWindow", "ФИО:"))
self.label_2.setText(_translate("MainWindow", "Алгебра:"))
self.label_3.setText(_translate("MainWindow", "Русский:"))
self.label_4.setText(_translate("MainWindow", "Химия:"))
self.label_5.setText(_translate("MainWindow", "Физика:"))
self.label_6.setText(_translate("MainWindow", "Литература:"))
self.label_7.setText(_translate("MainWindow", "География:"))
self.label_8.setText(_translate("MainWindow", "История:"))
self.label_9.setText(_translate("MainWindow", "Общество:"))
self.label_10.setText(_translate("MainWindow", "Информатика:"))
self.label_11.setText(_translate("MainWindow", "ОБЖ:"))
self.label_12.setText(_translate("MainWindow", "Физкульеура:"))
self.label_13.setText(_translate("MainWindow", "Итоговые:"))
class GOGO(QMainWindow, Dialog):
def __init__(self, value, p=None, pp=None):
super().__init__()
self.p = p
self.pp = pp
self.value = value
self.setupUi(self)
print(self.value) #<--- вывести переменную