''' Tk_PIL_Image_url.py
get a .jpg image from the internet and show it with
PIL and Tkinter

used PIL fork Pillow from:
Windows installer:
Pillow-2.2.1.win32-py2.7.exe or

tested with Python27 and Python33  by  vegaseat  14nov2013

from PIL import Image
from PIL import ImageTk
import io
    # Python2
    from urllib2 import urlopen
    import Tkinter as tk
except ImportError:
    # Python3
    from urllib.request import urlopen
    import tkinter as tk

# get a URL based image from the internet
# if the url was very long, split it in half
part1 = "http://uploads.neatorama.com/wp-content/"
part2 = "uploads/2011/05/cogtrain-500x688.jpg"
url = part1 + part2
fin = urlopen(url)
# read into a memory stream
s = io.BytesIO(fin.read())
pil_image = Image.open(s)
# let PIL determine the size info

# create Tkinter window
root = tk.Tk()

# convert PIL image to something Tkinter can handle
tk_image = ImageTk.PhotoImage(pil_image)

# show the image in a label
label = tk.Label(root, image=tk_image)


@JeffGrigg the downvoter, this is a code snippet, not a thread. You might like to look a little more carefully before asking what the OP's question is :)

Edited 3 Years Ago by Assembly Guy