python - 为什么我的操作系统无法打开新窗口来显示图像?
问题描述
我已将默认应用程序 --gimp 设置为在我的操作系统(debian 11 + lxde)中打开图像。
下面的 python 代码将在您的默认图像查看器中打开图像:
打开一个新窗口以显示图像
>>> from PIL import Image
>>> img = Image.open('test.png')
>>> img.show()
为什么在我的操作系统中执行时没有打开新窗口并且 gimp 开始显示图像?
解决方案
要在 Debian 中安装 matplotlib,请运行sudo apt install python3-matplotlib
. 使用 matplotlib Python 模块中的 pyplot 显示图像,如下所示。
import matplotlib.pyplot as plt
from PIL import Image
plt.imshow(Image.open('test.png'))
plt.show()
或者安装 eog ,sudo apt install eog
您的原始代码将在新窗口中显示图像。请注意,如果图像很小,那么新窗口也会很小,您可能不会注意到它是打开的。
推荐阅读
- c - C 语言:REST 客户端
- javascript - 将其更改为 jquery
- javascript - 满足条件时从数组中删除对象
- javascript - 通过访问父窗口在 iFrame 中创建 javascript 对象
- java - 为JAVA接口的默认方法实现普通接口的控制器
- android - 获取 UpdateEngine 在 AB OTA 应用程序中的空对象引用上
- html - 如何在一行上有两个内联 div,但响应式扩展并将所有其他内容向下推
- python - 在 Python 中语音转文本时遇到问题
- flutter - 如何在颤振中为 ios 和 android 检测模拟位置
- javascript - 编译 ejs 时在 partials\messages.ejs 中的参数列表后缺少 )