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

Recommended Answers

All 2 Replies

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.

Thank you Miss Ene, that works great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.