-1

When I run the code, it clearly displays the login scren, however whenever I try to enter details and submit, it gives back "AttributeError: 'NoneType' object has no attribute 'get", therefore why?

from tkinter import *
from tkinter import ttk

root = Tk()
root.title("Test_Login")
root.geometry("750x500+270+100")

def sayHello():
    e_text = e1.get()
    name_var2 = e2.get()
    Label(main, text=e_text + " " + name_var2).grid(row=4, column=0, columnspan=2)
    

main = Frame(root, width=700, height=498)
label1 = Label(main, text="First Name", font=("Arial", 12)).grid(row=0, column=0, padx=5, pady=5)

e1 = ttk.Entry(main, width= 30, font=('Century 12')).grid(row=0, column=1, padx=5, pady=5)

label2 = Label(main, text="Last Name", font=("Arial", 12)).grid(row=1, column=0, padx=5, pady=5)
e2 = ttk.Entry(main, width= 30,font=('Century 12')).grid(row=1, column=1, padx=5, pady=5)

Checkbutton(main, text = "I aggree to the terms and conditions", \
                 onvalue = 1, offvalue = 0).grid(row=3, column=0, columnspan=2, sticky=W)

btn = Button(main, text="LOGIN", font=("Arial", 15), bg="#1a94ff", command=sayHello).grid(row=2, column=0, columnspan=2)


main.place(relx=0.5, rely=0.5, anchor=CENTER)


root.mainloop()
  • 3
    What does the `grid()` method return? – Samwise Dec 10 '21 at 15:54
  • 1
    Don't call methods like `.grid()` or `.pack()` when assigning the variable. Assign the widget to the variable first, then use `variable.grid(...)` – Barmar Dec 10 '21 at 16:54

1 Answers1

0

You need to split the Entry creation up into two things: 1. variable declaration and 2. positioning, because the positioning functions return nothing (alias None). Only the constructors actually give you the wanted Entry objects.

So,

e2 = ttk.Entry(main, width= 30,font=('Century 12')).grid(row=1, column=1, padx=5, pady=5)

would become

e2 = ttk.Entry(main, width= 30,font=('Century 12'))
e2.grid(row=1, column=1, padx=5, pady=5)

Same thing for e1 or every other Label/Tkinter Widget you want to use later

Banana
  • 2,295
  • 1
  • 8
  • 25