gpt4 book ai didi

python - Tkinter GIF 不显示

转载 作者:行者123 更新时间:2023-11-30 23:06:35 24 4
gpt4 key购买 nike

我的 gif 被卡住“-”(不显示/动画,但在 tkinter 中工作)。我尝试了所有其他方法但仍然不起作用,代码:

    import tkinter as tk
from tkinter import *

def animate(self):

global pic

pic = PhotoImage(file="/home/arnaldo/Desktop/b.gif")

print("called1")

self.canvas = Canvas(width=350, height=233, bg='white')
self.canvas.pack(expand=YES, fill=BOTH)
self.canvas.create_image((0, 0), image=pic, anchor=NW)

class run(tk.Tk):

def __init__(self, *args, **kwargs):

tk.Tk.__init__(self, *args, **kwargs)

animate(self)

run().mainloop()

最佳答案

Tkinter 不会自动显示动画 gif。您必须通过循环加载每个帧来自己制作动画。

参见Play Animations in GIF with Tkinter

如果您的问题是根本看不到任何图像,则可能是由于图像被垃圾收集所致。

参见Cannot Display an Image in Tkinter

关于python - Tkinter GIF 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32594217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com