This article describes how Python uses Tkinter to display network pictures. Share to everyone for your reference. The implementation method is as follows:
"' tk_image_view_url_io.py display an image from a URL using Tkinter, PiL and Data_stream tested with Python27, and Pytho N33 by Vegaseat 01mar2013 ' "Import IO # allows for image formats" other than GIF from PIL import image, imagetk try: # Python2 import Tkinter as TK urllib2 import urlopen except importerror: # Python3 Import Tkinter as TK from Urllib.request import Urlopen root = Tk. Tk () # Find yourself A-on-Internet web page on the "Right click", under Properties copy the A ddress) #url = "Yun_qi_img/logo.gif" # or use image previously downloaded to tinypic.com #url = "Yun_qi_img/w6sjn6.jpg" ur L = "yun_qi_img/34g8vo5.jpg" image_bytes = Urlopen (URL). read () # internal data file Data_stream = Io. Bytesio (image_bytes) # Open as a PIL image object Pil_image = Image.open (data_stream) # optionally show image info # get t He is the image W, h = pil_image.size # split off image file name fname = Url.split ('/') [-1] sf = "{} ({}x{})". Format (FNAMe, W, h) root.title (SF) # convert PIL Image object to Tkinter photoimage object tk_image = Imagetk.photoimage (pil_image) # put the ' image ' on a typical widget label = tk. Label (Root, Image=tk_image, bg= ' Brown ') label.pack (padx=5, pady=5) Root.mainloop ()
I hope this article will help you with your Python programming.