Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

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()
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content