May 2018
Beginner to intermediate
452 pages
11h 26m
English
Now that we're working with all Ttk widgets, we can update our ValidatedMixin class with some dynamic styling.
We'll begin in the __init__() method by creating a Style object:
style = ttk.Style()
Since this is a mixin class, we don't know the original style name of the widget we're mixing with, so we'll have to fetch that.
Remember that we can do this with winfo_class():
widget_class = self.winfo_class()
validated_style = 'ValidatedInput.' + widget_class
After getting the widget class, we're creating a derivative style by prepending ValidatedInput to it. In order to toggle our input appearance between error and non-error appearances, we'll create a style map that switches with the state of the invalid state flag. ...