Tkinter GIF不显示 [英] Tkinter GIF not display

查看:160
本文介绍了Tkinter GIF不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gif冻结为-"(未显示/设置为动画,但在tkinter之外有效).我以其他所有方式尝试了很多,但是仍然无法正常工作,代码:

My gif is freeze '-' (not displayed/animated, but works out of tkinter). I tried so hard all other ways but still not work, the code:

    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.您必须通过循环加载每一帧来自己制作动画.

Tkinter doesn't automatically show animated gifs. You will have to do the animation yourself by loading each frame in a loop.

请参见使用Tkinter在GIF中播放动画

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

If your problem is that you're not seeing any image at all, it's probably due to the image being garbage-collected.

请参见无法在Tkinter中显示图像

这篇关于Tkinter GIF不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆