Reputation: 1014
I keep receiving the following error no matter what image url I try to use:
line 76, in <module>
radar = Label(root, image = im)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2556, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2055, in __init__
(widgetName, self._w) + extra + self._options(cnf))
TclError: image "<PIL.PngImagePlugin.PngImageFile image mode=RGBA size=538x190 at 0x105D4A830>" doesn't exist
Here is a snippet of code:
import pywapi, pprint, string, urllib, io
from Tkinter import *
from PIL import Image, ImageTk
fd = urllib.urlopen("http://www.google.com/images/srpr/logo11w.png")
imgFile = io.BytesIO(fd.read())
im = Image.open(imgFile)
image = Label(root, image = im)
image.grid(row = 7, column = 1)
I believe using a Label requires a PhotoImage and I am unsure of how to best proceed. Thank you.
Upvotes: 0
Views: 984
Reputation: 238131
For me the following code works. Please check if you do same:
import urllib, io
from Tkinter import *
from PIL import Image, ImageTk
root = Tk()
fd = urllib.urlopen("http://www.google.com/images/srpr/logo11w.png")
imgFile = io.BytesIO(fd.read())
im = ImageTk.PhotoImage(Image.open(imgFile)) # <-- here
image = Label(root, image = im)
image.grid(row = 7, column = 1)
root.mainloop()
Basically, I added PhotoImage and pass this to Label. Also check if you have zlib. Pillow does not read png by itself. It relays on external libraries.
Upvotes: 2