Hello,
I'm wondering how I can pass my userInputName and userInputPassword to my validate function.
I thought this was the correct way of doing it (because that's how I did it in my terminal version) but apparently it's not because I don't get the Success print messages from the validate function.
For example: If I type in Admin as the Name, and 1234 as the Password. I get:
What am I doing wrong, and how do I fix it?
Thanks in advance.
A Chunk of my LoginScreen.py (My LoginScreen GUI Code):
I'm wondering how I can pass my userInputName and userInputPassword to my validate function.
I thought this was the correct way of doing it (because that's how I did it in my terminal version) but apparently it's not because I don't get the Success print messages from the validate function.
For example: If I type in Admin as the Name, and 1234 as the Password. I get:
Output:The Login Button was clicked
Name: Admin
Password: 1234
But no: Success! You are now logged in as: Admin, messageWhat am I doing wrong, and how do I fix it?
Thanks in advance.
A Chunk of my LoginScreen.py (My LoginScreen GUI Code):
#---------------------------------- #Store Name and Password def LoginClicked(self): userInputName = self.NameInput.text() userInputPassword = self.PasswordInput.text() #Print in terminal for testing: print("The Login Button was clicked") print("Name: " + userInputName) print("Password: " + userInputPassword) #Go to validate function validate(userInputName, userInputPassword) #---------------------------------- #--------------------------------------------------------------- # Validate Function -> Validates user #--------------------------------------------------------------- #Pass in user and password variables from login function #Check if the user is valid (registered in database) -> Give access to inventory program #If user is not valid -> return to login #-->TODO: Write the user and current date to a file to keep track of logins def validate(userInputName, userInputPassword): if StandardUsers().get(userInputName) == userInputPassword: print('Success! You are now logged in as: ' + userInputName) #Switch from this screen to the MainMenu Screen #mainMenu() return True if SuperUsers().get(userInputName) == userInputPassword: print('Success! You are now logged in as: ' + userInputName) #Switch from this csreen to the AdminMenu Screen #adminMenu() else: return #---------------------------------------------------------------My UserDatabase.py:
#------------------------------------------------------------------------------------- #UserDatabase.py #------------------------------------------------------------------------------------- #This is where all valid users are stored #------------------------------------------------------------------------------------- def StandardUsers(): users = { "Bob" : 1234, "Jim" : 5678 } return users def SuperUsers(): admins = { "Admin" : 1234, "Joe" : 0000, "Randall" : 1111 } return adminsFull code (If Interested):
from PyQt5 import QtCore, QtGui, QtWidgets from UserDatabase import StandardUsers, SuperUsers class Ui_Loginscreen(object): def setupUi(self, Loginscreen): Loginscreen.setObjectName("Loginscreen") Loginscreen.resize(1108, 895) Loginscreen.setStyleSheet("background-color: rgb(0, 170, 255);") self.centralwidget = QtWidgets.QWidget(Loginscreen) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.Header = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(20) font.setBold(True) font.setWeight(75) self.Header.setFont(font) self.Header.setAlignment(QtCore.Qt.AlignCenter) self.Header.setObjectName("Header") self.gridLayout.addWidget(self.Header, 0, 0, 1, 1) self.formLayout_2 = QtWidgets.QFormLayout() self.formLayout_2.setObjectName("formLayout_2") self.NameLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.NameLabel.setFont(font) self.NameLabel.setObjectName("NameLabel") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.NameLabel) self.NameInput = QtWidgets.QLineEdit(self.centralwidget) self.NameInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.NameInput.setText("") self.NameInput.setObjectName("NameInput") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.NameInput) self.PasswordLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.PasswordLabel.setFont(font) self.PasswordLabel.setObjectName("PasswordLabel") self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.PasswordLabel) self.PasswordInput = QtWidgets.QLineEdit(self.centralwidget) font = QtGui.QFont() font.setFamily("Wingdings") self.PasswordInput.setFont(font) self.PasswordInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.PasswordInput.setText("") self.PasswordInput.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.PasswordInput.setObjectName("PasswordInput") self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.PasswordInput) self.label = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(8) font.setItalic(True) self.label.setFont(font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.label) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.formLayout_2.setItem(3, QtWidgets.QFormLayout.FieldRole, spacerItem) self.LoginButton = QtWidgets.QPushButton(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.LoginButton.setFont(font) self.LoginButton.setStyleSheet("background-color: rgb(211, 211, 211);\n" "border-style: outset;\n" "border-width: 2px;\n" "border-radius: 15px;\n" "border-color: black;\n" "padding: 4px;\n" "") self.LoginButton.setObjectName("LoginButton") self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.LoginButton) self.gridLayout.addLayout(self.formLayout_2, 1, 0, 1, 1) Loginscreen.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(Loginscreen) self.statusbar.setObjectName("statusbar") Loginscreen.setStatusBar(self.statusbar) self.retranslateUi(Loginscreen) QtCore.QMetaObject.connectSlotsByName(Loginscreen) def retranslateUi(self, Loginscreen): _translate = QtCore.QCoreApplication.translate Loginscreen.setWindowTitle(_translate("Loginscreen", "E.I.S")) self.Header.setText(_translate("Loginscreen", "Electronic Inventory System (E.I.S)")) self.NameLabel.setText(_translate("Loginscreen", "Name")) self.PasswordLabel.setText(_translate("Loginscreen", "Password")) self.label.setText(_translate("Loginscreen", "\n" "\n" "\n" "\n" "Electronic Inventory System (E.I.S)\n" "Version: 2.6\n" "Developed By: Paglia Industries\n" "Last Updated: 05/11/2022\n" "\n" "\n" "")) self.LoginButton.setText(_translate("Loginscreen", "Log In")) #------------------------------------------ #Actions #------------------------------------------ #When the Login button is clicked -> LoginClicked Function LoginButton = self.LoginButton LoginButton.clicked.connect(self.LoginClicked) #------------------------------------------ #---------------------------------- #Store Name and Password def LoginClicked(self): userInputName = self.NameInput.text() userInputPassword = self.PasswordInput.text() #Print in terminal for testing: print("The Login Button was clicked") print("Name: " + userInputName) print("Password: " + userInputPassword) #Go to validate function validate(userInputName, userInputPassword) #---------------------------------- #--------------------------------------------------------------- # Validate Function -> Validates user #--------------------------------------------------------------- #Pass in user and password variables from login function #Check if the user is valid (registered in database) -> Give access to inventory program #If user is not valid -> return to login #-->TODO: Write the user and current date to a file to keep track of logins def validate(userInputName, userInputPassword): if StandardUsers().get(userInputName) == userInputPassword: print('Success! You are now logged in as: ' + userInputName) #Switch from this screen to the MainMenu Screen #mainMenu() return True if SuperUsers().get(userInputName) == userInputPassword: print('Success! You are now logged in as: ' + userInputName) #Switch from this csreen to the AdminMenu Screen #adminMenu() else: return #--------------------------------------------------------------- if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Loginscreen = QtWidgets.QMainWindow() ui = Ui_Loginscreen() ui.setupUi(Loginscreen) Loginscreen.show() sys.exit(app.exec_())