Currently, our data model object is only created in the on_save() method, and is recreated every time the user saves. Some of the other callbacks we're going to write will need access to the model as well, so instead we'll create a single data model instance that can be shared by all the methods when the Application class is started or whenever a new filename is chosen. Let's take a look at the following steps:
- First, edit the Application.__init__() method right after the default_filename is created:
self.filename = tk.StringVar(value=default_filename) self.data_model = m.CSVModel(filename=self.filename.get())
- Next, the on_file_select() method needs to recreate the data_model object whenever the filename is changed.