Linux 拨号vps windows公众号手机端

PyQt5中怎么显示消息框

lewis 9年前 (2016-10-16) 阅读数 9 #程序编程
文章标签 pyqt5

在PyQt5中显示消息框可以使用QMessageBox类。以下是一个简单的例子:

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

class Example(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Message box example')

        self.showMessageBox()

    def showMessageBox(self):
        QMessageBox.information(self, 'Information', 'This is an information message box')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

在这个例子中,我们创建了一个简单的窗口,并在窗口中显示了一个信息消息框。您可以通过调用QMessageBox的静态方法(如information、question、warning等)来显示不同类型的消息框。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门