Dynamically adjusting the Spinbox range

Our ValidatedSpinbox method seems adequate for most of our fields. But consider the Height fields for a moment. It would not make any sense for the Mini height value to be more than the Max height value, or for the Median height value not to be between them. Is there some way we can work this kind of interdependent behavior into our class?

We can! To do this, we'll rely on the tracing feature of Tkinter variables. A trace is essentially a hook into the .get() and .set() methods of variables that allows you to trigger any Python function or method when a variable is read or changed.

The syntax is as follows:

sv = tk.StringVar()
sv.trace('w', some_function_or_method)
The first argument to .trace() indicates ...

Get Python GUI Programming - A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.