PyQt5实战——《退出显示弹窗提醒》

演示效果

附源码

import sys

from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication

class Example(QWidget):

    def __init__(self):

        super().__init__()

        self.initUI()

    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_())

posted @ 2021-06-05 09:09  博客zhu虎康  阅读(389)  评论(0编辑  收藏  举报