Mar-28-2021, 08:10 PM
Thanks for your notes.
I have a main window
MainMenuWindow = tk.Tk()
tk.Button(MainMenuWindow,text = "login", fg = "black", width = "25", height = "1", command= partial(UserLogin2,MainMenuWindow)).grid(row = 13, column = 0,padx = 5, pady = 5,columnspan = 1)
tk.mainloop()
also this
def UserLogin2(MainMenuWindow):
attempt_made = False
user_record = ['someblankerrortext']
global login_verified
global run_program
global logged_in_user_record
login_verified = False
run_program = True
logged_in_user_record = [0,"","",0]
while login_verified == False and run_program == True:
LoginWindow = tk.TopLevel()
tk.Label(LoginWindow,text = "Please login with you Username and Password").grid(row = 0, column = 0,columnspan = 2, padx = 100, pady = 10)
if attempt_made:
tk.Label(LoginWindow,fg="red",text = "Incorrect username and/or password").grid(row = 5, column = 0,columnspan = 2)
tk.Label(LoginWindow,text = "Username: ").grid(row = 10, column = 0)
username = StringVar()
tk.Entry(LoginWindow,textvariable = username).grid(row = 10, column = 1)
tk.Label(LoginWindow,text = "Password: ").grid(row = 11, column = 0 )
password = StringVar()
tk.Entry(LoginWindow,textvariable = password,show = "*").grid(row = 11, column = 1)
tk.Button(LoginWindow,text = "OK", fg = "black", width = "25", height = "2", command= partial(UserLoginCheckPassword,username,password)).grid(row = 20, column = 0,padx = 5, pady = 0,columnspan = 1)
tk.Button(LoginWindow,text = "Quit", fg = "black", width = "25", height = "2", command= partial(LoginQuit,LoginWindow)).grid(row = 20, column = 1,padx = 5, pady = 0,columnspan = 1)
tk.mainloop()
attempt_made = True
return logged_in_user_record[0]
and
def UserLoginCheckPassword(input_username,input_password,):
global logged_in_user_record
username = input_username.get()
password = input_password.get()
print("\n\nin_user",input_username,", user "+username)
print("in_psw",input_password,", pswd "+password+"\n\n")
db_connect = sqlite3.connect(database_name) #connects to the database
db_cursor = db_connect.cursor()
db_cursor.execute("SELECT * FROM "+user_ID_table+" WHERE username == '" + username + "' AND password == '"+password+"'")
user_record = db_cursor.fetchall() #selects user record where password and username match and saves it as user_record
global login_verified
if user_record == []: #if the username and password do not match in a record then there data will not be stored.
login_verified = False
else:
login_verified = True
logged_in_user_record = user_record
return
if i run
UserLogin2()
NOT from the login button, but instead from the main code, it works, i have a box, ask 2 entry fields, its check the database, if its wrong, an error message is shown, and repeats until its correct, then returns the user record.
However if i run UserLogin2() from a menu button press, it does not have any value in the get().
i have changed the code to use tk.xxxxx
and some other changes
i have looked at simple dialog, but that is only 1 text entry fields
this is where i am stuck please!
however, if i
I have a main window
MainMenuWindow = tk.Tk()
tk.Button(MainMenuWindow,text = "login", fg = "black", width = "25", height = "1", command= partial(UserLogin2,MainMenuWindow)).grid(row = 13, column = 0,padx = 5, pady = 5,columnspan = 1)
tk.mainloop()
also this
def UserLogin2(MainMenuWindow):
attempt_made = False
user_record = ['someblankerrortext']
global login_verified
global run_program
global logged_in_user_record
login_verified = False
run_program = True
logged_in_user_record = [0,"","",0]
while login_verified == False and run_program == True:
LoginWindow = tk.TopLevel()
tk.Label(LoginWindow,text = "Please login with you Username and Password").grid(row = 0, column = 0,columnspan = 2, padx = 100, pady = 10)
if attempt_made:
tk.Label(LoginWindow,fg="red",text = "Incorrect username and/or password").grid(row = 5, column = 0,columnspan = 2)
tk.Label(LoginWindow,text = "Username: ").grid(row = 10, column = 0)
username = StringVar()
tk.Entry(LoginWindow,textvariable = username).grid(row = 10, column = 1)
tk.Label(LoginWindow,text = "Password: ").grid(row = 11, column = 0 )
password = StringVar()
tk.Entry(LoginWindow,textvariable = password,show = "*").grid(row = 11, column = 1)
tk.Button(LoginWindow,text = "OK", fg = "black", width = "25", height = "2", command= partial(UserLoginCheckPassword,username,password)).grid(row = 20, column = 0,padx = 5, pady = 0,columnspan = 1)
tk.Button(LoginWindow,text = "Quit", fg = "black", width = "25", height = "2", command= partial(LoginQuit,LoginWindow)).grid(row = 20, column = 1,padx = 5, pady = 0,columnspan = 1)
tk.mainloop()
attempt_made = True
return logged_in_user_record[0]
and
def UserLoginCheckPassword(input_username,input_password,):
global logged_in_user_record
username = input_username.get()
password = input_password.get()
print("\n\nin_user",input_username,", user "+username)
print("in_psw",input_password,", pswd "+password+"\n\n")
db_connect = sqlite3.connect(database_name) #connects to the database
db_cursor = db_connect.cursor()
db_cursor.execute("SELECT * FROM "+user_ID_table+" WHERE username == '" + username + "' AND password == '"+password+"'")
user_record = db_cursor.fetchall() #selects user record where password and username match and saves it as user_record
global login_verified
if user_record == []: #if the username and password do not match in a record then there data will not be stored.
login_verified = False
else:
login_verified = True
logged_in_user_record = user_record
return
if i run
UserLogin2()
NOT from the login button, but instead from the main code, it works, i have a box, ask 2 entry fields, its check the database, if its wrong, an error message is shown, and repeats until its correct, then returns the user record.
However if i run UserLogin2() from a menu button press, it does not have any value in the get().
i have changed the code to use tk.xxxxx
and some other changes
i have looked at simple dialog, but that is only 1 text entry fields
this is where i am stuck please!
however, if i