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()
为什么标签..。“标签”不会更新为当前帧,而只是显示为默认标签(灰色)?
发布于 2021-01-26 10:27:09
尝试将图像保存为全局变量,如下所示
num = 0
img = None
def animate():
global num
global img
print(num)
img = PhotoImage(file = "gif.gif", format = "gif -index {}".format(num))
label.configure(image = img)
num = (num+1)%180
screen.after(25, animate)
animate()
发布于 2021-01-26 10:51:04
最好使用Pillow
模块来处理GIF帧:
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()
https://stackoverflow.com/questions/65898458
复制相似问题