3

I'm trying to animate a gif using wx-Python (2.7). The code listed below works but i want to create a function that animates the gif for me, so i can use it elsewhere. I've tried searching the internet but i can only find code that animates the gif within the __init__ function. Any ideas?

# -*- coding: cp1252 -*-
import wx
import wx.animate
class MyPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.SetBackgroundColour("black")
        gif_fname = "skYmk.gif"
        gif = wx.animate.GIFAnimationCtrl(self, id, gif_fname, pos=(10, 10))
        gif.GetPlayer().UseBackgroundColour(True)
        gif.Play()
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "wx.animate.GIFAnimationCtrl()", size = (200, 220))
MyPanel(frame, -1)
frame.Show(True)
app.MainLoop()

1 Answer 1

8

I don't understand your issue.... what is the problem in doing something like this?

import wx
import wx.animate

class MyPanel(wx.Panel):

    def __init__(self, parent, id):

        wx.Panel.__init__(self, parent, id)
        self.SetBackgroundColour("black")
        gif_fname = "skYmk.gif"
        gif = wx.animate.GIFAnimationCtrl(self, id, gif_fname, pos=(10, 10))
        gif.GetPlayer().UseBackgroundColour(True)

        self.gif = gif

    def CallMeLater(self, play=True):

        if play:
            self.gif.Play()
        else:
            self.gif.Stop()

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "wx.animate.GIFAnimationCtrl()", size = (200, 220))
MyPanel(frame, -1)
frame.Show(True)
app.MainLoop()
1
  • I wasn't sure about the parameters that the CallMeLater function would take and also i didnt realize i had to do self.gif.Play(). Thank you, this will probably solve my issue. Commented Mar 6, 2012 at 11:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.