1
from tkinter import *

#Windows
logWin = Tk()
mainWin = Tk()
srchWin = Tk()
NTWin = Tk()

#Variables
userName="123"
password="123"
logFail = ""
userBox = Entry(logWin)
passBox = Entry(logWin)
EU = userBox.get()
EP = passBox.get()

#General Window
mainWin.withdraw()
srchWin.withdraw()
NTWin.withdraw()

#Command
def loginCmd():
    if EU == userName and EP == password:
        print ("hello")
    else:
        print("no")


#Login Window
logWin.title("Login")
logWin.geometry("200x70")

userBox.grid(row=0,column=1)
passBox.grid(row=1,column=1)

userLbl = Label(logWin,text="Username:")
userLbl.grid(row=0,column=0)
passLbl = Label(logWin,text="Password:")
passLbl.grid(row=1,column=0)
failLbl = Label(logWin,text=logFail)
failLbl.grid(row=2,column=0)

logBtn = Button(logWin,text="Login",command=loginCmd)
logBtn.grid(row=2,column=1)


mainloop()

I am trying to create a program that requires you to login however my if statement in my def of the command doesn't seem to work and I have no idea why.

screenshot of what happens

1 Answer 1

2

In order for it to work, you need to get value when you click the button not when the textbox is initialized. Therefore, if you change the login function to the following, your program should function as expected.

def loginCmd():
    if userBox.get() == userName and passBox.get() == password:
        print("hello")
    else:
        print("no")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.