我一直在尝试使用动画gif Tkinter.PhotoImage,但没有看到任何成功.它显示图像,但不显示动画.以下是我的代码:
root = Tkinter.Tk()
photo = Tkinter.PhotoImage(file = "path/to/image.gif")
label = Tkinter.Label(image = photo)
label.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
它在窗口中显示图像,就是这样.我认为这个问题与Tkinter.Label我有关,但我不确定.我找了解决方案,但他们都告诉我使用PIL(Python Imaging Library),这是我不想使用的东西.
有了答案,我创建了一些代码(仍然无效......),这里是:
from Tkinter import *
def run_animation():
while True:
try:
global photo
global frame
global label
photo = PhotoImage(
file = photo_path,
format = "gif - {}".format(frame)
)
label.configure(image = nextframe)
frame = frame + 1
except Exception:
frame = 1
break
root = Tk()
photo_path = "/users/zinedine/downloads/091.gif"
photo = PhotoImage(
file = photo_path,
)
label = …Run Code Online (Sandbox Code Playgroud)