Skip to content


A tree control to navigate the contents of your filesystem.

  • Focusable
  • Container


The example below creates a simple tree to navigate the current working directory.

from import App, ComposeResult
from textual.widgets import DirectoryTree

class DirectoryTreeApp(App):
    def compose(self) -> ComposeResult:
        yield DirectoryTree("./")

if __name__ == "__main__":
    app = DirectoryTreeApp()



Bases: Message

Posted when a file is selected.

Can be handled using on_directory_tree_file_selected in a subclass of DirectoryTree or in a parent widget in the DOM.


Name Type Description
path str

The path of the file that was selected.

Reactive Attributes

Name Type Default Description
show_root bool True Show the root node.
show_guides bool True Show guide lines between levels.
guide_depth int 4 Amount of indentation between parent and child.

Component Classes

The directory tree widget provides the following component classes:

Class Description
directory-tree--extension Target the extension of a file name.
directory-tree--file Target files in the directory structure.
directory-tree--folder Target folders in the directory structure.
directory-tree--hidden Target hidden items in the directory structure.

See also the component classes for Tree.

See Also