pyqt 关闭事件

__author__ = 'Administrator'

import sys
from  PyQt4 import QtGui

class MessageBox(QtGui.QWidget):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.setGeometry(300,300,250,150)
        self.setWindowTitle('messagebox')
    def closeEvent(self, event):
        reply=QtGui.QMessageBox.question(self,'Message',
                                         'Are you sure to quit?',QtGui.QMessageBox.Yes,
                                         QtGui.QMessageBox.No)
        if reply==QtGui.QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

app=QtGui.QApplication(sys.argv)
qb=MessageBox()
qb.show()
sys.exit(app.exec_())

 

posted @ 2014-06-08 21:44  yufenghou  阅读(2519)  评论(0编辑  收藏  举报