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

首頁 > 編程 > Python > 正文

python使用Tkinter顯示網絡圖片的方法

2019-11-25 17:39:50
字體:
來源:轉載
供稿:網友

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

''' 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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广饶县| 兴安盟| 安溪县| 铁岭市| 罗江县| 渑池县| 库车县| 如皋市| 邵武市| 大庆市| 延边| 淳安县| 甘洛县| 偃师市| 营山县| 虞城县| 汝州市| 林西县| 临洮县| 洛宁县| 青铜峡市| 安乡县| 肇源县| 滨州市| 红河县| 凌源市| 大庆市| 扎兰屯市| 辉县市| 邓州市| 白山市| 康平县| 黄浦区| 丰台区| 富宁县| 晋中市| 赞皇县| 阳朔县| 铜川市| 庆安县| 扶余县|