code: def print_tree(
      current_node,
      childattr="children",
      nameattr="name",
      indent="",
      last="updown",
  ):
      if hasattr(current_node, nameattr):
          name = lambda node: getattr(node, nameattr)
      else:
          name = lambda node: str(node)
  
      children = lambda node: getattr(node, childattr)
      nb_children = (
          lambda node: sum(
              nb_children(child) for child in children(node)
          )
          + 1
      )
      size_branch = {
          child: nb_children(child) for child in children(current_node)
      }
  
      """ Creation of balanced lists for "up" branch and "down" branch. """
      up = sorted(
          children(current_node), key=lambda node: nb_children(node)
      )
      down = []
      while up and sum(size_branch[node] for node in down) < sum(
          size_branch[node] for node in up
      ):
          down.append(up.pop())
  
      """ Printing of "up" branch. """
      for child in up:
          next_last = "up" if up.index(child) == 0 else ""
          next_indent = "{}{}{}".format(
              indent,
              " " if "up" in last else "│",
              " " * len(name(current_node)),
          )
          print_tree(child, childattr, nameattr, next_indent, next_last)
  
      """ Printing of current node. """
      if last == "up":
          start_shape = "┌"
      elif last == "down":
          start_shape = "└"
      elif last == "updown":
          start_shape = " "
      else:
          start_shape = "├"
  
      if up:
          end_shape = "┤"
      elif down:
          end_shape = "┐"
      else:
          end_shape = ""
  
      print(f"{indent}{start_shape}{name(current_node)}{end_shape}")
  
      """ Printing of "down" branch. """
      for child in down:
          next_last = (
              "down" if down.index(child) is len(down) - 1 else ""
          )
          next_indent = "{}{}{}".format(
              indent,
              " " if "down" in last else "│",
              " " * len(name(current_node)),
          )
          print_tree(child, childattr, nameattr, next_indent, next_last)
  
label_desc: Use image node_id 1 for calling a global function with example usage: print_tree(current_node, childattr, nameattr, indent, last) without return types