def getRelativePositionTupleToAncestor(win, ancestor):
    """
    Calculates relative pixel position of win to ancestor where ancestor
    is either parent, grandparent, grandgrandparent ... or None for
    absolute position.
    Returns a tuple with the position.
    """
    resultx = 0
    resulty = 0
    while win is not None and win is not ancestor:
        x, y = win.GetPositionTuple()
        resultx += x
        resulty += y
        
        win = win.GetParent()

    return (resultx, resulty)