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

Retrieving data from our form

Now that we're finished with the form, we need a way to retrieve data from it so it can be processed by the application. We'll create a method that returns a dictionary of the form's data and, as we did with our LabelInput objects, maintain the Tkinter convention of calling it get().

Add the following method to your form class:

    def get(self):        data = {}        for key, widget in self.inputs.items():            data[key] = widget.get()        return data

The code is simple: we loop through our instance's inputs object containing our LabelInput objects and build a new dictionary by calling get() on each variable.

This code demonstrates the power of both iterable objects and consistent naming schemes. If we had stored our inputs as discrete ...

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