首页 > 解决方案 > 为什么我的操作系统无法打开新窗口来显示图像?

问题描述

我已将默认应用程序 --gimp 设置为在我的操作系统(debian 11 + lxde)中打开图像。

在此处输入图像描述

下面的 python 代码将在您的默认图像查看器中打开图像:
打开一个新窗口以显示图像

>>> from PIL import Image                                                                                
>>> img = Image.open('test.png')
>>> img.show() 

为什么在我的操作系统中执行时没有打开新窗口并且 gimp 开始显示图像?

标签: pythonimagepython-imaging-library

解决方案


要在 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您的原始代码将在新窗口中显示图像。请注意,如果图像很小,那么新窗口也会很小,您可能不会注意到它是打开的。


推荐阅读