O'Reilly logo

Python GUI Programming with Tkinter by Alan D. Moore

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The ttk Treeview

The Treeview is a ttk widget designed to show columns of data in a hierarchical structure.

Perhaps the best example of this kind of data is a filesystem tree:

  • Each row can represent a file or directory
  • Each directory can contain additional files or directories
  • Each row can have additional data properties, such as permissions, size, or ownership information

To explore how Treeview works, we'll create a simple file browser with some help from pathlib.

In previous chapters, we used os.path to work with file paths. pathlib is a new addition to the Python 3 standard library that provides a more object-oriented approach to paths.

Open a new file called treeview_demo.py and start with this template:

import tkinter as tk from ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required