0

I'm taking the input for a name in Tkinter, but it's giving an error when I want to check if only alphabets are entered:

t1=Label(text="Name:")
t1.place(x=40,y=100)
name=Entry(t)
if name.isalpha():
    print("Valid")
else:
    print("Invalid")

How do I check the validity of the input?

1 Answers1

0

You want to check the value of your input field. Use name.get().isalpha().

name is just a instance of Entry. You want the value of this entry field. You can get this by calling get() on the Entry instance.

isalpha() is defined on strings only.

10o
  • 80
  • 1
  • 8
  • You should also mention that they need to wait to call that code until after the user has a chance to enter something. As written, the OP's code will run a millisecond after creating the entry widget. – Bryan Oakley Mar 19 '20 at 17:38