Python PyQt5:如何使用PyQt5显示错误消息 [英] Python PyQt5: How to show an error message with PyQt5
本文介绍了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包含错误-消息特定的对话框类 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显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文