【发布时间】:2017-01-24 03:43:02
【问题描述】:
我正在尝试从 python2 转换为 python3 的程序使用PIL python 图像库。
我尝试从网络下载缩略图以在 tkinter 风格的 gui 中显示。这是我认为有问题的代码行:
# grab the thumbnail jpg.
req = requests.get(video.thumb)
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))
# now this is in PhotoImage format can be displayed by Tk.
plabel = tk.Label(tf, image=photo)
plabel.image = photo
plabel.grid(row=0, column=2)
程序停止并给出一个TypeError,这是backtrce:
Traceback (most recent call last): File "/home/kreator/.local/bin/url-launcher.py", line 281, in <module>
main()
File "/home/kreator/.local/bin/url-launcher.py", line 251, in main
runYoutubeDownloader()
File "/home/kreator/.local/bin/url-launcher.py", line 210, in runYoutubeDownloader
photo = ImageTk.PhotoImage(Image.open(StringIO(req.content)))
TypeError: initial_value must be str or None, not bytes
这里如何满足python3的要求?
【问题讨论】:
标签: python python-3.5