Building a model for settings persistence

As with any kind of data persistence, we need to start by implementing a model. As with our CSVModel class, the settings model needs to save and load the data, as well as define the layout of the settings data.

In the models.py file, let's start a new class as follows:

class SettingsModel:
    """A model for saving settings"""

Just as we did with our CSVModel class, we'll need to define our model's schema:

    variables = {
        'autofill date': {'type': 'bool', 'value': True},
        'autofill sheet data': {'type': 'bool', 'value': True}
     }

The variables dictionary will store both the schema and the values for each item. Each setting has a dictionary listing the data type and default value (we could list other attributes ...

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.