Python PyQt5:如何使用 PyQt5 显示错误消息 [英] Python PyQt5: How to show an error message with PyQt5

查看:199
本文介绍了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 显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆