Resetting our form

We're almost done with our form class, but there's one more method needed. After each save of the form, we're going to need to reset it to empty fields; so, let's add a method to do that by performing the following steps:

  1. Add this method to the end of the form class:
    def reset(self):        for widget in self.inputs.values():            widget.set('')
  1. As with our get() method, we're iterating through the input dictionary and setting each widget to an empty value. 
  2. To make sure our application behaves consistently, we should call reset() immediately after the application loads, clearing out any Tk defaults that we might not want.
  3. Back up to the last line of __init__() and add the following code line:
        self.reset()

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.