国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 施秉县| 衡阳县| 江华| 怀柔区| 吴桥县| 阜新市| 大同市| 孝昌县| 磐安县| 即墨市| 犍为县| 濉溪县| 鄱阳县| 望城县| 社旗县| 蓬安县| 南部县| 尚志市| 花莲县| 原阳县| 阳泉市| 东至县| 眉山市| 铜川市| 嵊泗县| 乌兰浩特市| 志丹县| 泰兴市| 岳阳县| 海南省| 余庆县| 麦盖提县| 合水县| 丰宁| 龙岩市| 贵德县| 朝阳县| 鱼台县| 轮台县| 天镇县| 商洛市|