A validating mixin class

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:

  1. 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)
  1. 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__() ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.