A better check is:

    if window is None: