'''Tk_Canvas_Image_url.py display an image obtained from an internet web page in Tkinter tested with Python27 and Python33 by vagaseat 21nov2012 ''' import io import base64 try: # Python2 import Tkinter as tk from urllib2 import urlopen except ImportError: # Python3 import tkinter as tk from urllib.request import urlopen root = tk.Tk() root.title("display a website image") # a little more than width and height of image w = 520 h = 320 x = 80 y = 100 # use width x height + x_offset + y_offset (no spaces!) root.geometry("%dx%d+%d+%d" % (w, h, x, y)) # this GIF picture previously downloaded to tinypic.com image_url = "http://i46.tinypic.com/r9oh0j.gif" image_byt = urlopen(image_url).read() image_b64 = base64.encodestring(image_byt) photo = tk.PhotoImage(data=image_b64) # create a white canvas cv = tk.Canvas(bg='white') cv.pack(side='top', fill='both', expand='yes') # put the image on the canvas with # create_image(xpos, ypos, image, anchor) cv.create_image(10, 10, image=photo, anchor='nw') root.mainloop()
Edited by Ene Uran
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.