Trying to open a home window after completing the login page

Viewed 22
        self.pushButton = QPushButton(self.verticalWidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.clicked.connect(self.login)
        self.verticalLayout_2.addWidget(self.pushButton)
        
        self.pushButton2 = QPushButton(self.verticalWidget)
        self.pushButton2.setObjectName(u"pushButton2")
        self.verticalLayout_2.addWidget(self.pushButton2)
        self.pushButton2.setDisabled(True)

    def login(self):
        email = self.emailLineEdit.text()
        password = self.passwordLineEdit.text()
        if email and password is not None:
            mydb = mc.connect(
                host="localhost",
                user="root",
                password=os.getenv('mysqlpass'),
                database="cinedeck")

            mycursor = mydb.cursor()
            query = f"SELECT email, password FROM user_info WHERE email = '{email}'"
            mycursor.execute(query)
            result = mycursor.fetchone()
            mydb.close()
            if result:
                if result[1] == password:
                    QMessageBox.about(self, "Success ✅", "Successfully logged into Cinedeck! Click again to continue.")
                    self.pushButton2.setDisabled(False)
                    self.pushButton2.clicked.connect(self.openhomescreen)
                else:
                    QMessageBox.about(self, "Error ⚠️", "Incorrect Password!")
                
            else:
                QMessageBox.about(self, "Error ⚠️", "Account does not exist!")
        else:
            QMessageBox.about(self, "Error ", "Please Enter Email or Password.")
            
    def openhomescreen(self):
        self.selfhomewindow.setupUi(self)

Could you suggest an easier method to open another window after the login. I tried doing a QMessageBox message that would open the new window when the button on it is clicked but I'm not able to figure out how to do it.

0 Answers
Related