我想用python3和tkinter创建一个虚拟宠物风格的游戏。到目前为止,我有主窗口,并开始放置标签,但我遇到的问题是播放动画GIF。我在这里搜索并找到了一些答案,但他们一直在抛出错误。我发现使用PhotoImage的gif的索引位置在一定范围内持续。用tkinter在python中播放GIF动画
# Loop through the index of the animated gif
frame2 = [PhotoImage(file='images/ball-1.gif', format = 'gif -index %i' %i) for i in range(100)]
def update(ind):
frame = frame2[ind]
ind += 1
img.configure(image=frame)
ms.after(100, update, ind)
img = Label(ms)
img.place(x=250, y=250, anchor="center")
ms.after(0, update, 0)
ms.mainloop()
当我在“pyhton3 main.py”终端运行此我得到以下错误:
_tkinter.TclError: no image data for this index
我是什么俯瞰或彻底离开了呢?
这里是链接到GitHub的仓库看到完整的项目:VirtPet_Python
提前感谢!
难道你不应该检查'ind'永远不会超过100吗?也许'ind%= 100'? –