Fixing the on_save() method

The error handling portion of on_save() is fine, but after the if errors: block, we'll start changing things:

        data = self.recordform.get()
        try:
            self.data_model.save_record(data)

We no longer need to extract the row number or pass it into save_record(), and we can delete the handling of IndexError since SQLModel will not raise that exception. We also need to rewrite the updating of inserted_rows and updated_rows.

Remove all the code in this method after the call to self.status.set(), and replace it with this:

 key = (data['Date'], data['Time'], data['Lab'], data['Plot']) if self.data_model.last_write == 'update': self.updated_rows.append(key) else: self.inserted_rows.append(key) self.populate_recordlist() if self.data_model.last_write ...

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.