Skip to content

How can I indent a Rich Tree? #1642

Answered by willmcgugan
ncoish asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the Padding class for this. There is a shortcut that adds padding to the left. Here's an example:

>>> from rich.padding import Padding
>>> from rich import print
>>> from rich.tree import Tree
>>> tree = Tree("foo")
>>> tree.add("bar")
<rich.tree.Tree object at 0x7feb2c5347f0>
>>> print(tree)
foo
└── bar
>>> print(Padding.indent(tree, 5))
     foo
     └── bar

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ncoish
Comment options

Answer selected by ncoish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants