PyQT5 Exit Confirmation
This is a small post explaining how you can add an exit confirmation to your PyQT5 code.
Simply add this code to your MainWindow class:
Remember to:
[PyQT5] from PyQt5.QtWidgets import QMessageBox
[PySide2] from PySide2.QtWidgets import QMessageBox
def closeEvent(self, event):
quit_msg = "Are you sure you want to exit the program?"
reply = QMessageBox.question(self, 'Message',
quit_msg, QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
Ubuntu Message Box:
Comments
Post a Comment