欧美国产另类久热|951超碰伊人久久|伊人影视久久久久|色婷婷亚洲小电影|色东京热69XX|婷婷玖玖深爱网|加勒比东京热网站|无码A级毛片在线观看|一级a毛一级a看|中文字幕人妻欧美

python使用Tkinter顯示網(wǎng)絡圖片的方法
來源:易賢網(wǎng) 閱讀:2758 次 日期:2015-04-28 11:40:03
溫馨提示:易賢網(wǎng)小編為您整理了“python使用Tkinter顯示網(wǎng)絡圖片的方法”,方便廣大網(wǎng)友查閱!

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

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

?

''' tk_image_view_url_io.py

display an image from a URL using Tkinter, PIL and data_stream

tested with Python27 and Python33 by vegaseat 01mar2013

'''

import io

# allows for image formats other than gif

from PIL import Image, ImageTk

try:

# Python2

import Tkinter as tk

from urllib2 import urlopen

except ImportError:

# Python3

import tkinter as tk

from urllib.request import urlopen

root = tk.Tk()

# find yourself a picture on an internet web page you like

# (right click on the picture, under properties copy the address)

#url = ""

# or use image previously downloaded to tinypic.com

#url = ""

url = ""

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 the size of 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()

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

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:python使用Tkinter顯示網(wǎng)絡圖片的方法
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)