The implementation look complex for a tree traversal, why you didn't go recursive ?

E.g.:
```python
def walk(widget, loopback=False, index=None):
    # we pass index only when we are going on the parent.
    # so don't yield the parent as well.
    if index is None:
        index = len(widget.children)
        yield widget

    # traverse the children first
    for child in reversed(widget.children[:index]):
        for walk_child in walk(child):
            yield walk_child

    # if we want to continue with our parent, just do it
    if loopback and widget.parent:
        parent = widget.parent
        # there is a possibily where the parent is incorrectly linked
        if widget not in parent.children:
            return
        index = parent.children.index(widget)
        for walk_child in walk(parent, loopback=loopback, index=index):
            yield walk_child
```

By the way, i would prefer to have an instance method for that no? Instead of walk(b), use b.walk() ?