Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

python - How can I display an image using Pillow?

I want to display a gif image using Pillow

Here is my simple code:

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

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

But nothing happens...

All help will be appreciated

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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')

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...