python-3.x - How to display image in python Tkinter from url
问题描述
How to display image of "https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg" this url in my tkinter project. is there is any way to do that.
解决方案
urllib.requrest.urlopen()
下面是一个使用andPillow
模块从 URL 显示图像的简单示例:
from urllib.request import urlopen
import tkinter as tk
from PIL import ImageTk
image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg"
root = tk.Tk()
data = urlopen(image_url)
image = ImageTk.PhotoImage(data=data.read())
tk.Label(root, image=image).pack()
root.mainloop()
推荐阅读
- ats - 为什么这个模板在单个文件中工作而不是跨文件工作?
- excel - 在 vba 中,我得到一个未设置的对象变量(错误 91)
- sql - SQL:使用百分比对表进行每月细分
- javascript - HTML 脚本捕获文本并使用自己的值执行事件
- google-apps-script - Google 表格高级 Google 服务 URL 缩短器 403 错误:禁止
- javascript - 如果 polyfill 脚本下载失败会怎样?
- git - Git 卡在 git pull upstream master
- python - 使用 python3 和 urbllib 的 PUT 方法 - 标头
- actionscript-3 - Actionscript 有数学规范吗?
- javascript - vuex store 模块操作中“this”的值是如何确定的?