Can I display animated images like an animated GIF file using Python code?

You need to use the wxPython GUI toolkit to do that:

# experiment with the wx.animate.GIFAnimationCtrl() widget
# needs wxPython installed

import wx
import wx.animate

class AnimatedGif(wx.Panel):
    """class to show an animated gif image on a panel"""
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        #self.SetBackgroundColour("black")
        # pick an animated GIF filename you have in the working folder
        ag_fname = "ag_puppy.gif"
        try:
            ag = wx.animate.GIFAnimationCtrl(self, id, ag_fname, pos=(10, 10))
            parent.SetTitle(ag_fname)
        except:
            pass
        ag.GetPlayer().UseBackgroundColour(True)
        ag.Play()


app = wx.PySimpleApp()
frame = wx.Frame(None, id=-1, title="need animated gif file", size=(300, 300))
AnimatedGif(frame, id=-1)
frame.Show(True)
app.MainLoop()

I think something like this is in the snippets.

Attachments AG_puppy.gif 6.34 KB
This article has been dead for over six months. Start a new discussion instead.