PyQt5 消息对话框

QMessageBox类提供了一个消息对话框,用于通知用户或询问用户问题并接收答案。

消息对话框分为五种,分别是information,question,warning,critical,abort。

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox

class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.resize(250, 155) self.setWindowTitle('title') self.show() # 重写closeEvent()事件方法 def closeEvent(self, event): # 显示消息对话框 reply = QMessageBox.question(self, 'Message', "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if reply == QMessageBox.Yes: event.accept() else: event.ignore() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())

QMessageBox  options:

posted @ 2020-01-16 10:14  PIPO2  阅读(886)  评论(0编辑  收藏  举报