Let's apply our knowledge of multiple inheritance to build a mixin that will give us some boilerplate validation logic by performing the following steps:
- Open data_entry_app.py and start the class before your Application class definition:
class ValidatedMixin: """Adds a validation functionality to an input widget""" def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs)
- We start this class as usual, though we're not subclassing anything this time. The constructor also has an extra argument called error_var. This will allow us to pass in a variable to use for the error message; if we don't, the class creates its own. The call to super().__init__() ...