def get_upper_parentwidget(widget, parent_position: int):
    """This function replaces this:
          self.parentWidget().parentWidget().parentWidget()
       with this:
          get_upper_parentwidget(self, 3)

    :param widget: QWidget
    :param parent_position: Which parent
    :return: Wanted parent widget
    """
    while parent_position > 0:
        widget = widget.parentWidget()
        parent_position -= 1
    else:
        return widget