国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用Tkinter顯示網(wǎng)絡圖片的方法

2020-02-23 00:51:08
字體:
來源:轉載
供稿:網(wǎng)友

本文實例講述了python使用Tkinter顯示網(wǎng)絡圖片的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

''' tk_image_view_url_io.pydisplay an image from a URL using Tkinter, PIL and data_streamtested with Python27 and Python33 by vegaseat 01mar2013'''import io# allows for image formats other than giffrom PIL import Image, ImageTktry:  # Python2  import Tkinter as tk  from urllib2 import urlopenexcept ImportError:  # Python3  import tkinter as tk  from urllib.request import urlopenroot = tk.Tk()# find yourself a picture on an internet web page you like# (right click on the picture, under properties copy the address)#url = "http://www.google.com/intl/en/images/logo.gif"# or use image previously downloaded to tinypic.com#url = "http://i48.tinypic.com/w6sjn6.jpg"url = "http://i50.tinypic.com/34g8vo5.jpg"image_bytes = urlopen(url).read()# internal data filedata_stream = io.BytesIO(image_bytes)# open as a PIL image objectpil_image = Image.open(data_stream)# optionally show image info# get the size of the imagew, h = pil_image.size# split off image file namefname = url.split('/')[-1]sf = "{} ({}x{})".format(fname, w, h)root.title(sf)# convert PIL image object to Tkinter PhotoImage objecttk_image = ImageTk.PhotoImage(pil_image)# put the image on a typical widgetlabel = tk.Label(root, image=tk_image, bg='brown')label.pack(padx=5, pady=5)root.mainloop()

希望本文所述對大家的Python程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 溧水县| 寻乌县| 荥经县| 沙坪坝区| 汉寿县| 兴安盟| 清原| 丽水市| 九台市| 张家界市| 石柱| 乐平市| 海淀区| 昆明市| 马尔康县| 沁水县| 奇台县| 湘潭县| 武陟县| 容城县| 会理县| 南宫市| 天等县| 湘西| 灌云县| 儋州市| 桂阳县| 湟中县| 汝城县| 泸溪县| 苍山县| 万年县| 宝山区| 锡林浩特市| 平塘县| 永吉县| 泌阳县| 连州市| 都匀市| 山阳县| 木里|