Adding a load_record() method

The last thing to add in our view is a method for loading in a new record. This method will need to set up our form with a given row number and data dictionary from the controller.

Let's call it load_record() as follows:

    def load_record(self, rownum, data=None):

The first thing we should do is set the form's current_record value from the rownum provided:

        self.current_record = rownum

Recall that rownum could be None, indicating that this is a new record.

Let's check for that by executing the following code:

        if rownum is None:
            self.reset()
            self.record_label.config(text='New Record')

If we're going to be inserting a new record, we simply want to reset the form, then set the label to indicate that this is a new ...

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.