![](/img/trans.png)
[英]When trying to display an image with a URL on tkinter, i get the error that there is no module named PIL
[英]i get an error when trying to add an image to python tkinter
嗨,所以将此图像与 my.py 文件放在同一目录中。 我将图像从“background.jpg”更改为“background.gif”,因为我听说当我 hover 我的 cursor 超过 file=background.gif 时它会向我显示图像以便它可以读取它但是当我尝试运行时. 它给了我一个错误并说“无法识别图像文件“background.gif”中的数据”
from tkinter import *
root = Tk()
photo = PhotoImage(file="background.gif")
label = Label(root, image=photo)
label.pack()
root.mainloop()
我认为这里的问题确实是(如 acw1668 提到的),因为您没有使用图像转换器来转换图像,而只是简单地将文件重命名为 .gif,这不是更改文件格式的正确方法,并且可能会损坏有时归档。 在线使用 jpg 到 gif 转换器可以解决此问题并为您提供有效的 gif:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.