Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Last active August 27, 2020 09:22
Show Gist options
  • Save DataSolveProblems/8758c82d68b8978ec4b762e0d6883c74 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/8758c82d68b8978ec4b762e0d6883c74 to your computer and use it in GitHub Desktop.
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QMessageBox)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
def closeEvent(self, event):
reply = QMessageBox.question(self, 'Window Close', 'Are you sure you want to close the window?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
event.accept()
print('Window closed')
else:
event.ignore()
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = MainWindow()
demo.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment