Tkinter Entries with if statements

hi guys

im trying to output a message based on what was entered in the tkinter Entry but i keep getting an error after I click on login

. please help

from tkinter import *
from tkinter.ttk import *

root = Tk()

field_username = Entry(root).grid(column=1,row=0)

user_name = Label(root,text='enter your user Name').grid(column=0, row=0)

def say():
    if field_username.get() == 'test':
        message = Label(root, text='you are logged in').grid(row=2, column=1)

Button(root, text='login',command=say).grid(column=0, row=2)

Read the error first. It basically says field_username is None type.
Now, think about why it is None type. There is only one place where the error can happen because you only assigned it on line 8.

Why is that line giving you None type?
It’s because .grid() returns None.

So your assumption about .grid() is incorrect. It doesn’t return Entry.
To fix this, call it on a separate line.

field = Entry(root)
1 Like

thank you very much :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: