Validation in Tkinter
Tkinter's validation system is one of those parts of the toolkit that is less than intuitive. It relies on the following three configuration options that we can pass into any input widget:
validate
: This option determines which type of event will trigger the validation callbackvalidatecommand
: This option takes the command that will determine if the data is validinvalidcommand
: This option takes a command that will run ifvalidatecommand
returnsFalse
This seems pretty straightforward, but there are some unexpected curves.
The values we can pass to validate
are as follows:
Validates string | Triggers when |
| It is none that turns off validation |
| The user enters or selects the widget |
| The user leaves the widget |
| Either |
| The user enters text in the widget |
|
|
The validatecommand
argument is where things get tricky. You might think this takes the name of a Python function or method, but that's not quite it. Instead, we...