Python uses Tkinter to display network pictures _python

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.