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

Populating the Treeview

Now that we have our Treeview widget, we'll create a populate() method to populate it with data:

    def populate(self, rows):
        """Clear the treeview & write the supplied data rows to it."""

The rows argument will take a list of the dict data types, such as what is returned from model. The idea is that the controller will fetch a list from the model and then pass it to this method.

Before refilling Treeview, we need to empty it:

        for row in self.treeview.get_children():
            self.treeview.delete(row)

The   get_children() method of Treeview returns a list of every row's iid. We're iterating this list, passing each iid to the Treeview.delete() method, which, as you'd expect, deletes the row.

With the Treeview cleared, we can ...

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