def closeEvent(self, *args, **kwargs): if os.path.exists('./~tmp'): os.remove('./~tmp') self.on_stopButton_clicked() return MainWindow.closeEvent(self, *args, **kwargs)