PyQt5 消息框

来源:互联网 发布:python运维开发视频 编辑:程序博客网 时间:2024/06/06 05:02
import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QMessageBoxclass Example(QWidget):    def __init__(self):        super().__init__()        self.initUI()    def initUI(self):        self.setGeometry(300, 300, 250, 150)        self.setWindowTitle('消息框')        self.show()    def closeEvent(self, event):        #关闭窗口触发以下事件        reply = QMessageBox.question(self, '消息框标题', '你确定要退出吗?', 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_()))

转载请注明作者与出处:http://blog.csdn.net/u013511642   王小涛_同學

0 0
原创粉丝点击