def on_tbxOutput_textEdited(self): if os.path.exists(self.ui.tbxOutput.text()): ofile = os.path.basename(str(self.ui.tbxOutput.text())) QApplication.beep() res = QMessageBox.question( self, 'Confirm Save As', ofile + ' already exists\n' + 'Do you want to replace it?', QMessageBox.Yes, QMessageBox.No) if res == QMessageBox.Yes: self.outfile = self.ui.tbxOutput.text() else: self.ui.tbxOutput.setText(self.outfile)