0

I'm trying to download a JPEG file from a URL and display it on a tkinter GUI window

This is the code I am trying to use to download and display the JPEG:

picURL = "https://graph.facebook.com/" + ID + "/picture"
picBytes= urlopen(picURL).read()
picData = io.BytesIO(picBytes)
picPil = Image.open(picData)
picTk = ImageTk.PhotoImage(picPil)
label_9 = Label(image = picTK, bg = "blue").pack()

The problem is that the image isn't showing up. All I get is a blue box. How can i make it so the picture is shown?

Thanks

Im using python 3.3 on windows

user2148781
  • 119
  • 1
  • 1
  • 9

2 Answers2

2

What library are you using to access the image? I would recommend requests. It automatically handles redirects for you:

import requests
import Image
from StringIO import StringIO

r = requests.get(https://graph.facebook.com/userID/picture)
im = Image.open(StringIO(r.content))
Chris Matta
  • 2,640
  • 3
  • 28
  • 45
0

Try with Tkinter

import Tkinter 
import Image, ImageTk
#open image and convert to byte format
im = Image.open('photo.jpg').convert2byte()
root = Tkinter.Tk()
tkimage = ImageTk.PhotoImage(im)
Tkinter.Label(root, image=tkimage).pack()
root.mainloop()

Also, see a related question Showing image in Gui

Community
  • 1
  • 1
Mihai8
  • 2,871
  • 1
  • 18
  • 27
  • that wont work, because i dont have the image stored, i need to get it from the redirected link but by only knowing the first one – user2148781 Mar 14 '13 at 14:02