Mar-23-2021, 09:42 PM
Hi, I have trouble making get work if its called a from a button press...
If I run this in the main code, then it works fine.
Any ideas please?
Like nested entry/get doesnt work?
def UserLogin2(): 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 = tkinter.Tk() LoginWindow.geometry("500x300+300+300") menu_label = Label(LoginWindow,text = "Please login with you Username and Password").grid(row = 0, column = 0,columnspan = 2, padx = 100, pady = 10) if attempt_made: incorrect_label = Label(LoginWindow,fg="red",text = "Incorrect username and/or password").grid(row = 5, column = 0,columnspan = 2) username_label = Label(LoginWindow,text = "Username: ").grid(row = 10, column = 0) username = StringVar() username_entry = Entry(LoginWindow,textvariable = username).grid(row = 10, column = 1) password_label = Label(LoginWindow,text = "Password: ").grid(row = 11, column = 0 ) password = StringVar() password_entry = Entry(LoginWindow,textvariable = password,show = "*").grid(row = 11, column = 1) Multichoice_button_0 = Button(LoginWindow,text = "OK", fg = "black", width = "25", height = "2", command= partial(UserLoginCheckPassword,username,password, LoginWindow)).grid(row = 20, column = 0,padx = 5, pady = 0,columnspan = 1) Multichoice_button_1 = 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) LoginWindow.mainloop() attempt_made = True return logged_in_user_record[0] def UserLoginCheckPassword(input_username,input_password, LoginWindow): 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")
If I run this in the main code, then it works fine.
x = UserLogin2()but if I run this from a button press in another function, it all works the same, however the get() return blanks!?
login_button = Button(MainMenuWindow,text = "Login", fg = "black", width = "25", height = "1",command= partial( UserLogin2)).grid(row = 12, column = 0,padx = 5, pady = 5,columnspan = 1)The issue seems to be, if we have a tkinter window with buttons, then a button press creates another tkinter window which has an entry field, get() shows blank, but if the tkinter window with entry field if just called from the main code, not from another windows button press, then get() = the text you entered.
Any ideas please?
Like nested entry/get doesnt work?