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 显示错误消息


基础教程推荐
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01