Z
Z
zaordu2021-04-15 22:01:03
Python
zaordu, 2021-04-15 22:01:03

How to pass a local variable?

There is a code fragment from the class of the first window, I get logins using an SQL query and compare them with what is entered in lineedit:

class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow1):
    window_height = 500
    window_width = 600
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.clicked.connect(self.onClicked)
        self.pushButton.clicked.connect(self.close)
        self.pushButton_2.clicked.connect(self.onClicked1)
        self.pushButton_2.clicked.connect(self.close)
        self.exampleApp = Windowone()
        self.errorapp = Windowthree()
        self.exampleApp_2 = RegWindow()
        self.adminwin = admwin()

    def onClicked(self):
         connection = pymysql.connect(host='127.0.0.1',
                                     user='root',
                                     password='adminadmin',
                                     db='mydb',
                                     charset='utf8mb4', )
        print("connected!!")
        flaglog = 0
        flagpas = 0
        curs = connection.cursor()
        curs.execute("SELECT username FROM usr")
        logs = curs.fetchall()# выполнение запроса
        login = (self.lineEdit.text(),)
        passw = (self.lineEdit_2.text(),)
        for row in logs:
            if row == login:
                flaglog = 1
        if flaglog == 1:
            curs.execute("SELECT password FROM usr WHERE username = %s ", login[0])
            pas = curs.fetchall()
            if pas[0] == passw:
                flagpas = 1
        if flaglog == 1 and flagpas == 1 :
            self.exampleApp.show()
            print(login)
        else:
            self.errorapp.show()

How can I get the login local variable data in another window? Normal import does not see it, as I understand it, it only works with global variables.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jan, 2021-04-22
@Buchachalo

return login?
Or define some login variable in __init__ , and then in the self.get_login = login
exp = ExampleApp()
exp.get_login method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question