so im trying to make a user login system, when a user clicks sign up and enters their password and username, it appends both of those to a file, however I made the entry field in the function that is called when you click sign in, Now i have an error when trying to get the data from that entry
usr = (Usrfield).get()
NameError: name 'Usrfield' is not defined
this is my code:
from tkinter import *
from tkinter import messagebox
Homescreen = Tk()
def addattrs():
Signup = Tk()
Usrfield = Entry(Signup, width=50)
#Usrfield = signupinput.get(1.0, "end-1c") c
Usrfield.insert(0, "What is ur usr")
Usrfield.pack()
Pswrdfield = Entry(Signup, width=50)
Pswrdfield.insert(0, "Password?")
Pswrdfield.pack()
Homescreen.withdraw()
loginbtn = Button(Signup, text="sign up", command=createusr)
loginbtn.pack()
def login():
Login= Toplevel(Homescreen)
Login.geometry("750x250")
Login.title("New Window")
Label(Login, text="Youve logged in?", font=('Helvetica 17 bold')).pack(pady=30)
Homescreen.withdraw()
def signup():
#create window
Homescreen.withdraw()
addattrs()
def createusr():
usr = (Usrfield).get()
password = Pswrdfield.get()
with open("Usernames.txt", "a+") as usrs:
usrs.write(usr)
usrs.write("\n")
with open("Passwords.txt", "a+") as pswrds:
pswrds.write(password)
pswrds.write("\n")
#Create a label
Label(Homescreen, text= "Click the below button to Open a New Window", font= ('Helvetica 17 bold')).pack(pady=30)
#Create a button to open a New Window
to_login = Button(Homescreen, text="Login", command=login).pack()
to_signup = Button(Homescreen, text="Sign up", command=signup).pack()
Homescreen.mainloop()
I tried defining the new screen after the original one closed but the program stopped running before the code could execute