Skip to content

DirectoryTree

A tree control to navigate the contents of your filesystem.

  • Focusable
  • Container

Example

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

from textual.app import App, ComposeResult
from textual.widgets import DirectoryTree


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


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

Messages

FileSelected

The DirectoryTree.FileSelected message is sent when the user selects a file in the tree

  • Bubbles

Attributes

attribute type purpose
path str Path of the file.

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.

See Also

  • Tree code reference
  • Tree code reference