class AutoTool: main_window = None def __init__(self): if not self.main_window: self.main_window = MainWindow(getMainWindow()) self.main_window.show() def delete(self): if getIsPointerValid(self.main_window): self.main_window.deleteLater()