Validating user input
At first glance, Tkinter's selection of input widgets seems a little disappointing.
It gives us neither a true number entry that only allows digits, nor a truly keyboard-friendly, modern drop-down selector. We have no date inputs, email inputs, or other specially formatted input widgets.
Nevertheless, these weaknesses can become strengths. Because these widgets assume nothing, we can make them behave in a way that's appropriate to our specific needs. For example, alphabetical characters may seem inappropriate in a number entry, but are they? In Python, strings such as NaN
and Infinity
are valid float values; having a box that could increment numerals but also handle those string values may be very useful in some applications.
Of course, before we can tailor our widgets to our needs, we'll need to think about what exactly we want them to do. Let's do some analysis.
Strategies to prevent data errors
There is no universal...