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 包含一个 错误-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 显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python PyQt5:如何使用 PyQt5 显示错误消息
基础教程推荐
- 包装空间模型 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
