Im trying to make a sign up form using tkinter module which collects the username and password, and after that a log in form pops up so u have to type in your username and password again, but it isn't working.
i made two variables to store the name and passcode entered in the sign up form
sign_up_name = StringVar()
sign_up_code = StringVar()
after entering the name and code and storing it and then clicking the sign up button it opens and new form to log in.
I made a function which creates two new variables to store the name and passcode entered in log in form
log_in_name = StringVar()
log_in_code = StringVar()
and i also made the variables for the name and passcode in the signup form global
global sign_up_name
global sign_up_code
I then made the whole screen in the same function and also used textvariable = log_in_name and textvariable = log_in_code in the entries
then I made another function inside the same function which is called when the log in button is pressed and in that function I check if the log_in_name variable is the same as the sign_up_name and if the log_in_code is the same as the sign_up_code
if log_in_name.get() == sign_up_name.get()and log_in_code.get() == sign_up_code.get():
messagebox.showinfo("Loged In!", "Successfully Loged In!")
else:
messagebox.showwarning("Error!", "Wrong Name Or Passcode! Try Again!!")
but what happens is that the sign up part works perfectly but at the end it keeps displaying the error message even though I enter the same name and passcode in both the log in form and sign in form.
i even made it print the sign_up_name, log_in_name, sign_up_code, and log_in_code to see and for the sign_up_name and sign_up_code it would print whatever I entered in the entry, but for the log_in_code and log_in_name it would print nothing. I have no idea what's wrong and I even made the variables global everywhere. Please help. Here is the whole code if needed:
#importing modules
from tkinter import *
from tkinter import messagebox
#making the sign up screen
sc = Tk()
sc.geometry("450x450")
sc.configure(background="#F0F8FF")
sc.title("Sign Up")
#two string variables to store the name and passcode_login entered i n the sign up form
sign_up_name = StringVar()
sign_up_code = StringVar()
#function to check if length of name and mail and code is okay
def check():
sc.quit
if len(sign_up_name.get()) >= 3 and len(mailentry.get()) >= 10 and len(sign_up_code.get()) >= 6:
messagebox.showinfo("Account Created!" , "Account Created Succesfully! Please Login Again To View Your Report Card!")
print("Sign Up\nUsername: ", sign_up_name.get(), "\n Passcode: ", sign_up_code.get())
login()
else:
messagebox.showwarning("Error", "Please Make Sure Your Username Length Is Greater Than 3, Your Passcode Has More Than 6 Charecters, And Please Enter A Valid Email!")
#function to open the log in screen and check everything
def login():
log_in_name = StringVar() #variable to store the name enetered in log in screen
log_in_code = StringVar() #variable to store the passcode enetered in log in screen
#making both variables global so i can use them to check
global sign_up_name
global sign_up_code
#making the log in screen
wn = Tk()
wn.geometry("450x450")
wn.configure(background="#e8ffd6")
wn.title("Login")
#just labels
sign_label = Label(wn, text="Log In To See Your Report Card! " , font=("Beachday", 23, "normal"), fg="black", bg="#e8ffd6")
sign_label.pack()
name_label = Label(wn, text="Username: ", font=("Chicken Pie Height", 19,"normal"), fg="black", bg="#e8ffd6")
name_label.place(x = 30, y = 100)
passw = Label(wn, text="Passcode: ", font=("Chicken Pie Height", 19,"normal"), fg="black", bg="#e8ffd6")
passw.place(x = 30, y = 260)
#entries to get name and passcode
name_login = Entry(wn, bg="#d8ffb9", fg = "black", bd=1, textvariable = log_in_name, font = ("212 Baby Girl", 15, "normal"))
name_login.place(x = 200, y = 106)
code_login = Entry(wn, bg="#d8ffb9", fg = "black", bd=1, textvariable = log_in_code, font = ("212 Baby Girl", 15, "normal"))
code_login.place(x = 200, y = 266)
#log in button
log = Button(wn, text="Log In", font=("212 Baby Girl", 17, "bold"), bg="#d8ffb9", activebackground="#d8ffb9", command=logged)
log.place(x = 90, y = 350)
#cancel button to close screen
can = Button(wn, text="Cancel", font=("212 Baby Girl", 17, "bold"), bg="#d8ffb9", activebackground="#d8ffb9",command=quit)
can.place(x = 300, y = 350)
#function to check if the name and passcode entered in the log in form is the same as the one
#enetered in sign up form
def logged():
#making variables global to use them
global sign_up_name
global sign_up_code
#printing the name and passcode enetered in log in form (only for me to see if it was working)
print("Log In: \n Username: ", log_in_name.get() , "\nPasscode: ", log_in_code.get())
#condition to check if name and passcode given in login form is same as name and passcode
#given in sign up form
if log_in_name.get() == sign_up_name.get()and log_in_code.get() == sign_up_code.get():
#message box if name and passcode matched
messagebox.showinfo("Loged In!", "Successfully Loged In!")
else:
#gives error if not matched
messagebox.showwarning("Error!", "Wrong Name Or Passcode! Try Again!!")
#setting up sign up screen
#labels
sign_label = Label(sc, text="Sign Up To See Your Report Card! " , font=("Beachday", 23, "normal"), fg="black", bg="#F0F8FF")
sign_label.pack()
name_login_label = Label(sc, text="Username: ", font=("Chicken Pie Height", 19,"normal"), fg="black", bg="#F0F8FF")
name_login_label.place(x = 30, y = 100)
maill = Label(sc, text="Email: ", font=("Chicken Pie Height", 19,"normal"), fg="black", bg="#F0F8FF")
maill.place(x = 30, y = 180)
passw = Label(sc, text="Passcode: ", font=("Chicken Pie Height", 19,"normal"), fg="black", bg="#F0F8FF")
passw.place(x = 30, y = 260)
#entry for name
name_signUp = Entry(sc, bg="#eaf6fe", fg = "black", bd=1, textvariable = sign_up_name, font = ("212 Baby Girl", 15, "normal"))
name_signUp.place(x = 200, y = 106)
#entry for mail
mailentry = Entry(sc, bg="#eaf6fe", fg = "black", bd=1, font = ("212 Baby Girl", 15, "normal"))
mailentry.place(x = 200, y = 186)
#entry for code
code_signUp = Entry(sc, bg="#eaf6fe", fg = "black", textvariable = sign_up_code, bd=1, font = ("212 Baby Girl", 15, "normal"))
code_signUp.place(x = 200, y = 266)
#submit button
submit = Button(sc, text="Sign Up", font=("212 Baby Girl", 17, "bold"), bg="#ADD8E6", activebackground="#AFDCEB", command=check)
submit.place(x = 90, y = 350)
#cancel button
cancel = Button(sc, text="Cancel", font=("212 Baby Girl", 17, "bold"), bg="#ADD8E6", activebackground="#AFDCEB",command=quit)
cancel.place(x = 300, y = 350)
sc.mainloop()