def hierarchy(widget):
    """Return the widget hierarchy (from widget, down) as nested dicts.
    Each dict is as follows:
    {"path": path,
     "name": name,
     "id": (integer id),
     "widget": (widget),
     "class": class_string,
     "children": (...,
                  ...)}
    """
    _id = widget.winfo_id()
    return {"path": widget.winfo_pathname(_id),
            "name": widget.winfo_name(),
            "id": _id,
            "widget": widget,
            "class": widget.winfo_class(),
            "children":
                tuple([hierarchy(w)
                       for w in widget.winfo_children()])}