Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 765
Ziph0n Avatar asked Jan 25 '15 18:01

Ziph0n


People also ask

How do I display an image in HTML using Python?

To display image on a HTML page with Python Flask, we can pass the image path to the template from the view. Then we call render_template with the template file name, and the user_image argument set to the image path. to interpolate the user_image in the template.


1 Answers

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()
like image 62
unutbu Avatar answered Oct 04 '22 18:10

unutbu