How To Display A Png File From A Webpage On A Tk Label In Python?
I'm new to python and I'm on a windows 7 64 bit with python 3.3. I can display a gif image with the following code. However I can't make it work with png files. How to do that? Tha
Solution 1:
You should use PIL (or pillow). You can find pillow windows binary here.
Try following example after you install pillow:
from io import BytesIO
import urllib
import urllib.request
import tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
url = "http://imgs.xkcd.com/comics/python.png"with urllib.request.urlopen(url) as u:
raw_data = u.read()
im = Image.open(BytesIO(raw_data))
image = ImageTk.PhotoImage(im)
label = tk.Label(image=image)
label.pack()
root.mainloop()
Post a Comment for "How To Display A Png File From A Webpage On A Tk Label In Python?"