Tkinter显示失真图像

2024-04-27 00:06:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Tkinter显示gif,但是当加载gif时,它看起来很奇怪。我粘贴了原始gif和Tkinter中显示的gif的截图。这种情况不会只发生在一个gif上,而是发生在我使用的每个gif上。你知道吗

Gif原始帧:

enter image description here

在tkinter中看到的帧:

enter image description here

代码如下:

from Tkinter import *
import time as t

root = Tk()

frames = []
i = 0

while True:
    try:
        frames.append(PhotoImage(file='display.gif',format='gif -index %i' %(i)))
        i += 1
    except  TclError:
        break


def update(ind):
    if ind >= len(frames):
        ind = 0
    frame = frames[ind]
    ind += 1
    label.configure(image=frame)
    root.after(100, update, ind)

label = Label(root)
label.pack()
root.after(0,update,0)
root.mainloop()

Tags: importframes粘贴tkinter情况updaterootgif