如何使用 Pillow 显示图像? [英] How can I display an image using Pillow?

查看:22
本文介绍了如何使用 Pillow 显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Pillow 显示 gif 图像

I want to display a gif image using Pillow

这是我的简单代码:

from tkinter import *
from PIL import Image, ImageTk 
import tkinter as Tk 

image = Image.open("Puissance4.gif") 
image.show()

但是什么都没发生...

But nothing happens...

感谢所有帮助

谢谢!

推荐答案

PIL 提供了一个 show 方法,该方法尝试检测您的操作系统并选择一个合适的观众.在 Unix 上,它尝试调用 imagemagick 命令 displayxv.在 Mac 上它使用 open,在 Windows 上它使用......别的东西.

PIL provides a show method which attempts to detect your OS and choose an appropriate viewer. On Unix it tries calling the imagemagick command display or xv. On Macs it uses open, on Windows it uses... something else.

如果找不到合适的查看器,ImageShow._viewers 将是一个空列表.

If it can't find an appropriate viewer, ImageShow._viewers will be an empty list.

在 Raspbian 上,您需要安装图像查看器,例如 displayxvfim.(请注意,在网络上搜索会显示有许多可用的图像查看器.)然后您可以通过指定 command 参数告诉 PIL 使用它:

On Raspbian, you'll need to install an image viewer such as display, xv or fim. (Note a search on the web will show that there are many image viewers available.) Then you can tell PIL to use it by specifying the command parameter:

image.show(command='fim')

<小时>

要在 Tkinter 中显示图像,您可以使用以下内容:


To display an image in Tkinter, you could use something like:

from PIL import Image, ImageTk 
import tkinter as tk 

root = tk.Tk()
img = Image.open("image.gif")
tkimage = ImageTk.PhotoImage(img)
tk.Label(root, image=tkimage).pack()
root.mainloop()

这篇关于如何使用 Pillow 显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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