简体   繁体   中英

How to validate a entry for only non-integer values in Tkinter

I want to know can we validate a entry for string values only. Means you can't put any integer into the string. I know we can do similar one where we can disable entering the alphabetic values for a entry like this:

def only_numbers(char):
    return char.isdigit()

validation = parent.register(only_numbers)
entry = Entry(parent, validate="key", validatecommand=(validation, '%S'))

but, is there any similar way to disable non integer or alphabetic values from entering.

Thanks to @JacksonPRO for answering

def only_numbers(char):
    return char.isalpha()

validation = parent.register(only_alphabet)
entry = Entry(parent, validate="key", validatecommand=(validation, '%S'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM