'wxPython: animated gif as background

I want to play an animated gif as background in my application with buttons, static text and panels over it. I think I've almost reached the solution but I don't know if there is an easier way.

In the sample of code below I nest panels, I want to set the animation as the lower layer, but I'm not sure if the problem is that I need to update the panels to make the visible over the gif animation.

Any tip is welcomed :)

import wx
from wx.adv import Animation, AnimationCtrl


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = \
            kwds.get("style", 0) | wx.CAPTION | wx.CLOSE_BOX | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER
        wx.Frame.__init__(self, *args, **kwds)

        self.SetTitle("ParKING")
        _icon = wx.NullIcon
        _icon.CopyFromBitmap(wx.Bitmap('ico.png', wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)
        self.Center()

        sz1 = wx.BoxSizer()
        sz2 = wx.BoxSizer()
        sz3 = wx.BoxSizer()

        p1 = wx.Panel(self)
        p2 = wx.Panel(p1)
        p3 = wx.Panel(p2)

        p1.SetBackgroundColour(wx.RED)
        p2.SetBackgroundColour(wx.GREEN)
        p3.SetBackgroundColour(wx.BLUE)

        sz3.Add(p3, 1, wx.ALL | wx.EXPAND, 20)
        p2.SetSizer(sz3)
        sz2.Add(p2, 1, wx.ALL | wx.EXPAND, 20)
        p1.SetSizer(sz2)
        sz1.Add(p1, 1, wx.ALL | wx.EXPAND, 0)

        anim = Animation('fondo.gif',type=wx.adv.ANIMATION_TYPE_GIF)
        ctrl = AnimationCtrl(p1, -1, anim)
        ctrl.Play()

        self.SetSizer(sz1)
        self.Show()


class MyWindow(wx.Window):

    def __init__(self):
        wx.Window.__init__(self)
        frame = MyFrame(None, wx.ID_ANY, "")
        self.Create(frame)


class MyApp(wx.App):
    def OnInit(self):
        MyWindow()
        return True


if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source