<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # PyQt `QMessageBox` > 原文: [https://pythonbasics.org/PyQt-QMessageBox/](https://pythonbasics.org/PyQt-QMessageBox/) PyQt `QMessageBox`,您可以用來創建對話框。 這是一個經常在桌面上看到的彈出窗口。 它可能是單行消息,“確定要保存嗎?”消息或更高級的消息。 該消息框支持各種變體和按鈕。 在本課程中,您將學習如何創建信息對話框窗口。 ## 對話框 ### 初始窗口 創建一個帶有按鈕的窗口。 如果單擊按鈕,將彈出對話框。 (這也是 PyQt 初始化的地方。) ```py def window(): app = QApplication(sys.argv) win = QWidget() button1 = QPushButton(win) button1.setText("Show dialog!") button1.move(50,50) button1.clicked.connect(showDialog) win.setWindowTitle("Click button") win.show() sys.exit(app.exec_()) ``` 因此,讓我們看一下`showDialog()`。 ### 創建一個對話框 使用`QMessageBox()`創建一個對話框。 不要忘記從 PyQt5 導入它。 ```py from PyQt5.QtWidgets import QPushButton ``` 然后使用方法`setIcon()`,`setText()`,`setWindowTitle()`設置窗口裝飾。 您可以使用`setStandardButtons()`配置對話框按鈕。 ```py def showDialog(): msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Information) msgBox.setText("Message box pop up window") msgBox.setWindowTitle("QMessageBox Example") msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.buttonClicked.connect(msgButtonClick) returnValue = msgBox.exec() if returnValue == QMessageBox.Ok: print('OK clicked') ``` ![pyqt messagebox](https://img.kancloud.cn/99/b4/99b4bc2ce0d6f9c900bf23dda7152929_299x145.jpg) ### 可下載的代碼 您可以將以下代碼復制并粘貼到自己的計算機上,以測試其工作方式。 ```py import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox from PyQt5.QtGui import QIcon from PyQt5.QtCore import pyqtSlot def window(): app = QApplication(sys.argv) win = QWidget() button1 = QPushButton(win) button1.setText("Show dialog!") button1.move(50,50) button1.clicked.connect(showDialog) win.setWindowTitle("Click button") win.show() sys.exit(app.exec_()) def showDialog(): msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Information) msgBox.setText("Message box pop up window") msgBox.setWindowTitle("QMessageBox Example") msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.buttonClicked.connect(msgButtonClick) returnValue = msgBox.exec() if returnValue == QMessageBox.Ok: print('OK clicked') def msgButtonClick(i): print("Button clicked is:",i.text()) if __name__ == '__main__': window() ``` [下載示例](https://gum.co/pysqtsamples)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看