Skip to content

Instantly share code, notes, and snippets.

@saleph
Last active November 3, 2019 13:09
Show Gist options
  • Save saleph/97522ef6a2d9ed9aa882 to your computer and use it in GitHub Desktop.
Save saleph/97522ef6a2d9ed9aa882 to your computer and use it in GitHub Desktop.
[qt5] handling close event - msg box
__author__ = "tom"
import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def initUi(self):
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Message box')
self.show()
def closeEvent(self, event):
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment