-2

I am trying to submit the form submission using tkinter.But i got an error stating 'NoneType' object has no attribute 'get'.I don't know why it happend.

def onsubmit():
    
    email=email_entry.get()

    myconn = mysql.connector.connect(host = "localhost", user = "root",password = 
    "",database="project")
    cur = myconn.cursor()
    sql1="INSERT INTO 
    register(name,email,gender,qualification,courses,username,password)values(%s,%s,%s,%s,%s,%s,%s)"
    values=[(name,email,gender,qualification,check_list,username,password)]
    cur.executemany(sql1,values)
    myconn.commit()
    myconn .close()

global email_in

lemail=Label(root,text="Email",width=20,font=("bold",10)).place(x=80,y=180)
email_entry=Entry(root).place(x=240,y=180)

sub=Button(root,text="Submit",bg='brown',fg='white',width=20,command=onsubmit).place(x=160,y=480)

root.mainloop()

error shown in below

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\PYTHON\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:/Users/Softech/Desktop/pr.py", line 25, in onsubmit
    email=email_entry.get()
AttributeError: 'NoneType' object has no attribute 'get'
ABINBENNY
  • 29
  • 6

2 Answers2

2

The problem is very simple, instead of saying place() in the same line, instead say:

email_entry=Entry(root)
email_entry.place(x=240,y=180)

Now everything will be fixed.

This is because email_entry=Entry(root).place(x=240,y=180) return None, ie, when you use email_entry.get() you are saying email_entry=Entry(root).place(x=240,y=180).get() which does not exist in the first place and since email_entry=Entry(root).place(x=240,y=180) is None they give error, you received.

Extra fixes:

  • You can remove global in the main block since its of no use in there.
  • I think, your values should be a tuple rather than a tuple inside of list so change that to
values=(name,email,gender,qualification,check_list,username,password)

Cheers

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
0

Create a variable email_txt = StringVar()

modify this email_entry=Entry(root).place(x=240,y=180) to

email_entry=Entry(root, textvariable=email_txt).place(x=240,y=180)

In the function, modify

email=email_entry.get() to email=email_txt.get()

  • 3
    Yes, this is a way around, but if the user tries to delete whats inside of the entry box later on, itll give the same error, so its recommended to not use geometric managers in the same line as the declaration – Delrius Euphoria Sep 04 '20 at 11:26
  • 1
    Yeah, that's a valid point didn't think of that earlier –  Sep 04 '20 at 11:31