0

How can I restrict my entry box input to alphabet only? I've tried many methods from online but nothing seemed to work . . .

This was the approach I thought of:

window = Tk()

entry1 = Entry(window)
entry1.pack()

def submit():
    getinput = entry1.get()

    try:
        getinput != int(getinput)
    except ValueError:
        messagebox.showerror('Error', 'Letters only please')

window.bind('<Return>', lambda event: submit())

window.mainloop()

Unfortunately, this didn't work. It kind of works? But it considers alphabets an integer, I think.. Please help.

Sanchez
  • 55
  • 6
  • 1
    You could test the input against [a regex](https://stackoverflow.com/questions/6067592/regular-expression-to-match-only-alphabetic-characters)? – Ari Cooper-Davis Apr 23 '22 at 08:43
  • @AriCooper-Davis, thanks for the link and the suggestion. I had to learn about regular expressions since I've only know about them just now so yeah, and I was able to restrict my entry box input to alphabet only. Thanks! – Sanchez Apr 23 '22 at 12:46

0 Answers0