O'Reilly logo

Python GUI Programming with Tkinter by Alan D. Moore

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required