def isDescendantWidget(maybeParent, widget):
    """Return True if 'widget' is 'maybeParent' or a descendant of it.

    Widget parenthood is tested for Tk in this function.

    """
    if widget is maybeParent:
        return True
    else:
        return any(( isDescendantWidget(w, widget)
                     for w in maybeParent.winfo_children() ))