Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

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__() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content