溫馨提示×

PyQt5中怎么顯示消息框

小億
177
2024-03-12 17:41:41
欄目: 編程語言

在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等)來顯示不同類型的消息框。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女