我正试图从网站上获取图片,并将其显示在我的Tkinter脚本中。
from PIL import Image
import requests
from io import BytesIO
url = 'http://wakils.com/wp-content/uploads/2020/09/einsteinfessor4.png'
response = requests.get(url)
img = Image.open(BytesIO(response.content))
panel = tk.Label(root, image = img)
canvas1.create_window(600, 200, window=panel)
错误:
Exception has occurred: UnidentifiedImageError
cannot identify image file <_io.BytesIO object at 0x05458528>
File "D:\Python\EinsteinMatFes.py", line 24, in <module>
img = Image.open(BytesIO(response.content))