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