• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python使用Tkinter显示网络图片的方法

python使用Tkinter显示网络图片的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python3 tkinter,python中tkinter,python tkinter,python3.5 tkinter,python tkinter教程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python使用Tkinter显示网络图片的方法。分享给大家供大家参考。具体实现方法如下:

''' 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 = "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 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()
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python实现颜色空间转换程序(Tkinter)
  • 基于python的Tkinter实现一个简易计算器
  • Python基于Tkinter实现的记事本实例
  • Python基于Tkinter的HelloWorld入门实例
  • python使用Tkinter显示网络图片的方法
  • python使用Tkinter显示网络图片的方法
  • Python写的Tkinter程序屏幕居中方法
  • python的tkinter布局之简单的聊天窗口实现方法
  • python的tkinter布局之简单的聊天窗口实现方法

相关文章

  • python使用post提交数据到远程url的方法
  • 使用IronPython把Python脚本集成到.NET程序中的教程
  • Python 不同对象比较大小示例探讨
  • Python实现的多线程http压力测试代码
  • python实现根据主机名字获得所有ip地址的方法
  • python使用PyGame模块播放声音的方法
  • Python实现把json格式转换成文本或sql文件
  • Python模仿POST提交HTTP数据及使用Cookie值的方法
  • Python设计模式中单例模式的实现及在Tornado中的应用
  • 使用tensorboard可视化loss和acc的实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python使用cookielib模块操作cookie的实例教程
    • python 读写、创建 文件的方法(必看)
    • Python脚本实现格式化css文件
    • 详解Python中的多线程编程
    • 在Python中使用cookielib和urllib2配合PyQuery抓取网页信息
    • python开发环境PyScripter中文乱码问题解决方案
    • Python中super的用法实例
    • Python中的True,False条件判断实例分析
    • Python中splitlines()方法的使用简介
    • Python使用multiprocessing创建进程的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有