I wanted to start using pillow, but I ran into some problems:
At first, I thought I could simply pip install pillow
, so I activated my virtualenv and did exactly that. When it didn't worked, I realized that I need to install some dependencies for pillow (installation). I'm on Ubuntu 14.04. But even after I installed those dependencies and reinstalled pillow, the Code didn't work. Until I tried it outside of the virtualenv and pip
installed pillow on my main Python3.4 installation, where my Code suddenly worked.
import tkinter as tk
from PIL import Image, ImageTk
def show(img, text=""):
root = tk.Tk()
root.title(text)
photo = ImageTk.PhotoImage(img)
image_lbl = tk.Label(root, image=photo)
image_lbl.image = photo
image_lbl.pack()
root.mainloop()
show(Image.open("test.jpg"), text="Test")
Error:
Traceback (most recent call last):
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 176, in paste
tk.call("PyImagingPhoto", self.__photo, block.id)
_tkinter.TclError: invalid command name "PyImagingPhoto"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/Code/Python/main/test.py", line 15, in <module>
show(Image.open("test.jpg"), text="Test")
File "~/Code/Python/main/test.py", line 8, in show
photo = ImageTk.PhotoImage(img)
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 115, in __init__
self.paste(image)
File "~/Code/Python/venvs/main/lib/python3.4/site-packages/PIL/ImageTk.py", line 180, in paste
from PIL import _imagingtk
ImportError: cannot import name '_imagingtk'