-1

I am trying to retrieve a variable from a Tkinter Widget but I am running into this error message:

File "C:\Users\BABIR\PycharmProjects\nea_final_final_attempt\Sign_up.py", line 46, in signup
    if self.username_entry.get!=self.confirm_username_entry.get:
AttributeError: 'NoneType' object has no attribute 'get'

I am unsure as to what is causing this error to occur, here is the code as a whole:

from tkinter import *
from tkinter import messagebox

window = Tk()
window.geometry("1650x1000")
window.title("Sign up")


class sign_up_screen():
    def __init__(self, master):
        self.master = master
        self.master.geometry("1650x1000")
        self.master.title("Sign up")
        self.setup_window()

    def setup_window(self):
        signup_label = Label(self.master, text="sign up page", font=("Arial Bold", 50,), fg='#0066ff').pack()

        username_label=Label(self.master, text="username", font=("Arial Bold", 25,)).place(x=600,y=200)
        self.username_entry=Entry(width=10,font=("Arial",25)).place(x=770,y=200)

        password_label=Label(self.master,text="password", font=("Arial Bold", 25,)).place(x=600,y=250)
        self.password_entry=Entry(width=10,font=("Arial",25)).place(x=770,y=250)

        confirm_username_label=Label(self.master,text="confirm username", font=("Arial Bold", 25,)).place(x=467,y=300)
        self.confirm_username_entry=Entry(width=10,font=("Arial",25)).place(x=770,y=300)

        confirm_password_label=Label(self.master,text="confirm password", font=("Arial Bold", 25,)).place(x=467,y=350)
        self.confirm_password_entry=Entry(width=10,font=("Arial",25)).place(x=770,y=350)

        register_button=Button(self.master, text="sign up", font=("Arial Bold", 25,),
                               bg="black", fg="white",command=self.signup).place(x=750, y=500)








    def signup(self):

        #Function for the sign up purposes, this method does all the validation

        if self.username_entry.get!=self.confirm_username_entry.get:
            messagebox.showerror("Error","Usernames do not match")
            return

        if len(self.username_entry.get()) <6:
            messagebox.showerror("Error","Minimum of 6 characters for username")
            return

        if self.password_entry.get()!=self.confirm_password_entry.get():
            messagebox.showerror("Error","Passwrods do not match")
            return
        if len(self.password_entry.get())<6:
            messagebox.showerror("Error","Minimum of 6 characters for username.")
            return










s = sign_up_screen(window)

window.mainloop()

I expected a message box to pop up when the button is clicked and the entry fields were filled out incorrectly, however nothing happens when the button is clicked.

1 Answers1

1

You need to declare your Entry widgets separately from placeing them. The geometry manager methods (grid, pack, and place) all return None, so your variables are evaluating to None.

# Don't do this:
my_entry = Entry(root).place()
# my_entry == None
# Do this instead:
my_entry = Entry(root)
my_entry.place()
# my_entry == .!entry
JRiggles
  • 4,847
  • 1
  • 12
  • 27