如何使用枕头显示图像? [英] How can I display an image using 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命令display
或xv
.在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上,您需要安装图像查看器,例如display
,xv
或
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()
这篇关于如何使用枕头显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!