Search code examples
pythonpython-2.7user-interfacewxpython

Can't play animation in wxPython


Im trying to play GIF image, which i taken from preloaders site, in my frame:

class TestFrame(wx.Frame):

    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, -1, title, style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)

        self.animation = wx.animate.AnimationCtrl(self, pos=(40,40), size=(24, 24), name="AnimationCtrl")
        self.animation.LoadFile("./gui/icons/preloader.gif", wx.animate.ANIMATION_TYPE_GIF)
        self.animation.Play()

        size = (310, 150)
        self.SetSize(size)
        self.icon = wx.Icon('./gui/icons/app.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)
        self.Show()

In result ill will see only all gif (its looks like just imported image at frame). What i doing wrong?


Solution

  • I tested your code and it worked fine on my computer. I have python 2.7 and wxPython 3.0. If you still haven't solved your problem try using this code:

    import wx.animate
    
    class TestFrame2( wx.Frame ):
        def __init__( self, parent ):
            wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Testing!", pos = wx.DefaultPosition, size = ( 300,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.RESIZE_BORDER )
            self.m_animCtrl1 = wx.animate.AnimationCtrl( self, wx.ID_ANY, wx.animate.NullAnimation, ( 40,40 ), ( -1,-1 ), wx.animate.AC_DEFAULT_STYLE )
            self.m_animCtrl1.LoadFile( u"img.GIF" )
            self.m_animCtrl1.Play()
            self.Layout()
            self.Show()
            self.Centre( wx.BOTH )
    
    if __name__ == "__main__":
        App = wx.App()
        TestFrame2(None)
        App.MainLoop()