tags:

views:

414

answers:

2

I'm trying to validate the entry of text using Python/tkInter

def validate_text():
    return False


text = Entry(textframe, validate="focusout", validatecommand=validate_text)

where validate_text is the function - I've tried always returning False and always returning True and there's no difference in the outcome..? Is there a set of arguments in the function that I need to include?

Edit - changed from NONE to focusout...still not working

A: 

"Note that this option [validatecommand] is only used if the validate option is not NONE"

From http://effbot.org/tkinterbook/entry.htm#entry.Entry.config-method

balpha
thanks - I changed to 'focus', 'focusout' and 'key' and the only one that seems to work is 'key'..however I'm looking for a focusout event?
meade
A: 

I don't think the validatecommand does what you think it should do. It won't reject any input based on the return value. It doesn't matter if you return True or False, what you have to do is reset the value and maybe restore focus if you determine the value isn't valid.

In other words, your code is working properly, you just need to do something in your validate_text method if the data isn't valid.

Bryan Oakley