I am trying to create a login GUI using Tkinter in python. Everything works well for registering an account as the details are stored in a txt file, but when i use those details to login i get the error AttributeError: 'NoneType' object has no attribute 'get'. I don't see anything wrong with my code but here is the login funtion below:
def check_login():
login_username = username_login.get()
login_password = password_login.get()
with open(login_username_login+".txt", "r") as file:
#make sure this works. A space is needed after the readlines to mimic what is in the text file
if (file.readlines()+" ") == password_login:
Label(screen1, text = "Login Success", fg = "red", bg="#DFA0F1" ,font = ("calibri", 11)).pack()
else:
Label(screen1, text="Username/Password incorrect", fg = "red", bg="#DFA0F1").pack()
username_login and password_login are defined here:
def login():
global username_login
global password_login
username_login = StringVar()
password_login = StringVar()
top = Toplevel()
top.title("Login")
top.geometry("500x300")
top["bg"]="#DFA0F1"
Label(top, text="Login:", bg="#F3EF9D").pack()
username_label = Label(top, text="Username", bg="#AAF7C7").pack()
username_login = Entry(top, textvariable=username_label).pack()
password_label = Label(top, text="Password", bg="#AAF7C7").pack()
password_login = Entry(top, textvariable=password_label, show="*").pack()
login = Button(top, text="Login", height="1", width="10", bg="#AEF0F5", command=check_login).pack()