I am doing some image editing with the PIL libary. The point is, that I don't want to save the image each time on my HDD to view it in Explorer. Is there a small module that simply enables me to set up a window and display the image?

- 119,623
- 25
- 170
- 301

- 10,771
- 14
- 44
- 75
-
Display the image **how**? In a browser? – Sep 24 '12 at 18:38
-
in a python made window. Something like a window from pygame. I could do it in pygame, but i would like a better solution. – Bartlomiej Lewandowski Sep 24 '12 at 18:40
-
WxPython? Or is that too heavy weight? http://wxpython.org/ – grieve Sep 24 '12 at 18:40
-
1why dont you want to save it? – Joran Beasley Sep 24 '12 at 18:41
-
1lets say i have 100 small pictures to look through. It would be better if i could have all of them printed on my screen, without having to open them in some other program. I am not really familiar with wxpython. Is it simple? – Bartlomiej Lewandowski Sep 24 '12 at 18:44
-
1You're going to need some windowing library—whether pygame, wxPython, TkInter, PyQt, PyGtk, PyWin32, PyObjC, etc.—to open a window. Once you've got a window open, most of them make it trivial to display an image in that window. – abarnert Sep 24 '12 at 18:55
-
Another possibility is to script Explorer or some other program (e.g., through PyWin32COM) to do the display for you. – abarnert Sep 24 '12 at 18:56
-
@abarnert So which libary do you recommend? – Bartlomiej Lewandowski Sep 24 '12 at 19:28
-
PIL has lots of built-in integration with TkInter, and it's the only windowing library that comes built-in with Python. So, if you have no preference, maybe start with that. Most people who didn't grow up on it (or on Tcl/Tk) hate it, but if you're not doing anything complicated it should be easier to learn the basics of TkInter than to, e.g., get wx installed and then learn the basics of wx. On the other hand, if you already know pygame and already have it installed, it's a bit more work, but probably still easier than learning a whole new system. – abarnert Sep 24 '12 at 21:18
8 Answers
From near the beginning of the PIL Tutorial:
Once you have an instance of the Image class, you can use the methods defined by this class to process and manipulate the image. For example, let's display the image we just loaded:
>>> im.show()
Update:
Nowadays the Image.show()
method is formally documented in the Pillow fork of PIL along with an explanation of how it's implemented on different OSs.

- 119,623
- 25
- 170
- 301
-
it is actually what i was looking for, but i get a windows live photo gallery error. 0x800706ba – Bartlomiej Lewandowski Sep 24 '12 at 19:25
-
3That's because Windows live photo gallery is associated with the type of temporary file PIL created when you called the method -- which probably defaults to .bmp on Windows which doesn't support many of the capabilities of modern image file formats. Try setting the image format attribute explicitly to .png (i.e. `im.format = "PNG"`) before the `im.show()` call. – martineau Sep 24 '12 at 19:38
-
still the problem persists. I might actually try a window libary. – Bartlomiej Lewandowski Sep 24 '12 at 19:42
-
3PIL's built-in `show()` method is the simplest possible version of the "script some other program to show it". (On earlier Windows systems you'd end up with a whole bunch of MSPaint windows.) It was worth suggesting and trying even if it didn't work. You could actually do something similar, and almost as simple, by, say, explicitly launching MSPaint.exe on each image… – abarnert Sep 24 '12 at 21:19
-
3@abarnert: Actually the problem sounds like a [bug in Windows Live Photo Gallery 2011](http://support.microsoft.com/kb/2581947) and there's a newer version that can be [download](http://www.microsoft.com/en-us/downloaded/details.aspx?id=29219) that may fix the PIL `show()` problem. – martineau Sep 24 '12 at 21:33
-
-
-
@endolith: As I said in an earlier comment, `im.show()` will open the image with whatever the application is associated with the type of temporary file PIL creates, so probably "yes", if that happens to be XnView. Many applications automatically do this (or ask you if you want it done at installation time). PIL's default was likely picked so no third-party software would need to be installed. – martineau Jun 29 '15 at 15:51
-
Here's an [updated link](http://windows.microsoft.com/en-us/windows/download-windows-essentials#wetabs=we2012) to download a version of Windows Live Photo Gallery for various (older) versions of Windows. It's part of the Windows Essentials suite of programs. – martineau Jan 20 '16 at 10:47
-
Got a similar error that said something about the image could not be found as it was moved. But ran the same script again and this time was able to load the image using the default Photos app on a Windows10 machine with Fall Creators update. – ultrasounder Dec 14 '18 at 07:04
-
On Windows with an older version of PIL I found that it launched a program to open and display the file, but deleted the file before the program finished opening. I have an answer to that effect [here on SO](https://stackoverflow.com/a/8933913/5987). – Mark Ransom Jun 08 '20 at 18:20
I tested this and it works fine for me:
from PIL import Image
im = Image.open('image.jpg')
im.show()

- 13,566
- 7
- 90
- 104
-
1While this may answer the question (untested) it is best practice to provide an explanation with your code on SO. It is actually discouraged to give code only answers. – d_kennetz Mar 14 '19 at 20:11
-
2
-
3@kawingkelvin Question was "How to show PIL images on the screen?". You should seek answer for your specific situation elsewhere...perhaps here: https://stackoverflow.com/questions/55288657/image-is-not-displaying-in-google-colab-while-using-imshow – Hrvoje Mar 19 '20 at 05:36
-
1
You can use pyplot to show images:
from PIL import Image
import matplotlib.pyplot as plt
im = Image.open('image.jpg')
plt.imshow(im)
plt.show() # image will not be displayed without this

- 3,796
- 6
- 49
- 105

- 311
- 5
- 7
-
1Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Tyler2P May 01 '21 at 15:11
If you find that PIL has problems on some platforms, using a native image viewer may help.
img.save("tmp.png") #Save the image to a PNG file called tmp.png.
For MacOS:
import os
os.system("open tmp.png") #Will open in Preview.
For most GNU/Linux systems with X.Org and a desktop environment:
import os
os.system("xdg-open tmp.png")
import os
os.system("powershell -c tmp.png")

- 131
- 1
- 9
-
Feather, on MacOS, it won't necessarily open in Preview, but in the default for the file type. I was working with some large jpg files, which Preview converts to .png, taking about 20 seconds. Changing the jpg default to Chrome worked wonders... – John White Jul 27 '20 at 05:42
Maybe you can use matplotlib for this, you can also plot normal images with it. If you call show() the image pops up in a window. Take a look at this:

- 731
- 5
- 19
You can display an image in your own window using Tkinter, w/o depending on image viewers installed in your system:
import Tkinter as tk
from PIL import Image, ImageTk # Place this at the end (to avoid any conflicts/errors)
window = tk.Tk()
#window.geometry("500x500") # (optional)
imagefile = {path_to_your_image_file}
img = ImageTk.PhotoImage(Image.open(imagefile))
lbl = tk.Label(window, image = img).pack()
window.mainloop()
For Python 3, replace import Tkinter as tk
with import tkinter as tk
.

- 3,115
- 25
- 28
-
4Where did you see that the code involves saving the image to disk??? The question asks for a way to edit an image w/o having to save it on disk each time. But you must open the image from disk at least once in the beginning. Then you can process and view the image loaded in memory as 'img' as many times you like w/o involving any disk operation. – Apostolos Oct 26 '18 at 08:36
Yes, PIL.Image.Image.show() easy and convenient.
But if you want to put the image together, and do some comparing, then I will suggest you use the matplotlib. Below is an example,
import PIL
import PIL.IcoImagePlugin
import PIL.Image
import matplotlib.pyplot as plt
with PIL.Image.open("favicon.ico") as pil_img:
pil_img: PIL.IcoImagePlugin.IcoImageFile # You can omit. It helps IDE know what the object is, and then it will hint at the method very correctly.
out_img = pil_img.resize((48, 48), PIL.Image.ANTIALIAS)
plt.figure(figsize=(2, 1)) # 2 row and 1 column.
plt.subplots_adjust(hspace=1) # or you can try: plt.tight_layout()
plt.rc(('xtick', 'ytick'), color=(1, 1, 1, 0)) # set xtick, ytick to transparent
plt.subplot(2, 1, 1), plt.imshow(pil_img)
plt.subplot(2, 1, 2), plt.imshow(out_img)
plt.show()

- 6,105
- 2
- 37
- 45
This is what worked for me:
roses = list(data_dir.glob('roses/*'))
abc = PIL.Image.open(str(roses[0]))
PIL.Image._show(abc)

- 71
- 4