python图片外连httpwyuqi52cnimg1png获取图片然后用from PIL import Image ImageTk显示
以下是Python代码示例:
from PIL import Image, ImageTk
import urllib.request
url = "http://w.yuqi52.cn/img/1.png"
response = urllib.request.urlopen(url)
img_data = response.read()
image = Image.open(io.BytesIO(img_data))
# 将图像转换为Tkinter PhotoImage对象
photo = ImageTk.PhotoImage(image)
# 创建一个标签,显示图像
label = tkinter.Label(root, image=photo)
label.pack()
root.mainloop()
首先,我们使用urllib.request模块获取图像数据。然后,使用PIL模块打开图像,并将其转换为ImageTk.PhotoImage对象。最后,我们创建一个tkinter标签,将图像显示在其中。注意,tkinter窗口必须在mainloop()函数调用之前创建
原文地址: http://www.cveoy.top/t/topic/cPGY 著作权归作者所有。请勿转载和采集!