Pythonの基本3:ディレクトリ構造の表示できるパッケージTree
ディレクトリ構造の表示できるパッケージTree
- コマンドラインでディレクトリの構造を出力することが出来るパッケージTreeがあります
- Treeパッケージのインストールは以下のコマンドで簡単にインストールします
pip install Tree

Treeでディレクトリの構造を表示
Treeパッケージは実際のツリーの描画
- Treeパッケージはコマンドラインでディレクトリ構造表示だけではなく、実際のツリー描画も出来ます
- ツリーの描画例
from math import pi, radians as rad
from Tree.core import Tree
from PIL import Image
branches = (
(.5, rad(-30)),
(.6, rad(30)),
(.4, rad(60))
)
def main():
tree = Tree(
pos=(0, 0, 0, -500),
branches=branches
)
# Let the tree grow
tree.grow(10)
# Move the tree in the right position, so that the tree is completly in the image
tree.move_in_rectangle()
im = Image.new("RGB", tree.get_size(), (239, 239, 239))
tree.draw_on(im, (85, 25, 0, 128, 53, 21), (0, 62, 21), 10)
im.show()
if __name__ == '__main__':
main()
