Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

python - 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...