python - Tkinter 动画
问题描述
num = 0
def animate():
global num
print(num)
img = PhotoImage(file = "gif.gif", format = "gif -index {}".format(100))
label.configure(image = img)
num = (num+1)%180
screen.after(25, animate)
animate()
为什么标签...“标签”没有更新为当前帧,而是显示为默认标签(灰色)?
解决方案
Better use Pillow
module to handle the GIF frames:
from PIL import Image, ImageTk
...
image = Image.open("gif.gif") # load the image
def animate(num=0):
num %= image.n_frames
image.seek(num) # seek to the required frame
img = ImageTk.PhotoImage(image)
label.config(image=img)
label.image = img # save a reference of the image
label.after(25, animate, num+1)
animate()
推荐阅读
- java - 从 dao 获取并使用 RxJava 插入新线程
- python - 将 JSON 文件转换为 QR 码时出错
- visual-studio-code - 从 vscode 设置生成 .prettierrc?
- php - 如何将数据传递给dompdf?
- php - php : 将文件内容分成不同的文件
- javascript - 根据字符在字符串中的位置复制字符
- c# - 如何在 C# WinForms 中的 Main() 之后声明一个公共表单
- android - Flutter - 通过点击 n 屏幕隐藏/显示两个横幅
- javascript - 地图函数的返回
- kubernetes - Kubernetes:如何实现 0 停机时间