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:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM