我一直在尝试使用动画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) 我想通过从最好应该是不同的 GIF 中提取 15 帧来压缩 GIF 图像。
我正在使用 Python 和 Pillow 库,但我没有找到任何方法来获取Pillow 文档中GIF 的帧数。我也没有找到如何从 GIF 中提取特定帧,因为Pillow 限制了.
有没有办法提取帧而不需要遍历每个帧?是否有更高级的用于 GIF 处理的 Python 库?
我试图从我的gif图像显示动画.从我之前的问题,我发现Tkinter不会自动为图像制作动画.我的Tk界面显示图像的第一帧,当我点击按钮播放动画时,它什么也没做.这可能与与按钮关联的命令有关.这是代码:
from Tkinter import *
import Tkinter
root = Tk()
photo_path = "/users/zinedine/downloads/091.gif"
photo = PhotoImage(
file = photo_path
)
def run():
frame = 1
while True:
try:
photo = PhotoImage(
file = photo_path,
format = "gif - {}".format(frame)
)
frame = frame + 1
except Exception: # This because I don't know what exception it would raise
frame = 1
break
picture = Label(image = photo)
picture.pack()
picture.configure(run())
animate = Button(
root,
text = "animate",
command = …Run Code Online (Sandbox Code Playgroud)