Extract JPEG image from redirected URL and display it in GUI window

I am trying to download a jpeg file from a url and display it in a tkinter GUI window

This is the code I'm trying to use to load and display a 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 is not displayed. All I get is a blue box. How can I do this so that the image is displayed?

thanks

Im using python 3.3 for windows

0
source share
2 answers

What library do you use 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)) 
+2
source

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 related question Image Display in Gui

0
source

Source: https://habr.com/ru/post/1492472/


All Articles