Validating Entry in tkinter
Saul Spatz
saul.spatz at gmail.com
Mon Jul 25 07:46:36 EDT 2011
Thanks so much, this is great. I want to validate that the user is entering a string appropriate for bytes.fromhex. Here's how I modified your validate funtion:
def validate(before, after):
print(before, "-->", after)
#return after.isdigit()
return after[-1] in '1234567890abcdefABCDEF '
I also had to change validate="all" to validate="key" in the Entry construction, since otherwise, I go an IndexError when the widget gets the focus. (try...except also worked, but I only care about keystrokes.)
I didn't know about the register method; that's the key.
Thanks again,
Saul
More information about the Python-list
mailing list