本文介紹了Python PyQt5:如何使用 PyQt5 顯示錯誤消息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在普通 Python (3.x) 中,我們總是使用 tkinter 模塊中的 showerror() 來顯示錯誤消息,但是在 PyQt5 中我應該怎么做才能顯示完全相同的消息類型呢?
In normal Python (3.x) we always use showerror() from the tkinter module to display an error message but what should I do in PyQt5 to display exactly the same message type as well?
推薦答案
Qt 包含一個 錯誤-message 特定的對話框類 QErrorMessage
,您應該使用它來確保您的對話框符合系統標準.要顯示對話框,只需創建一個對話框對象,然后調用 .showMessage()
.例如:
Qt includes an error-message specific dialog class QErrorMessage
which you should use to ensure your dialog matches system standards. To show the dialog just create a dialog object, then call .showMessage()
. For example:
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Oh no!')
這是一個最小的工作示例腳本:
Here is a minimal working example script:
import PyQt5
from PyQt5 import QtWidgets
app = QtWidgets.QApplication([])
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Oh no!')
app.exec_()
這篇關于Python PyQt5:如何使用 PyQt5 顯示錯誤消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!