在wxPython中动画gif

时间:2012-03-05 20:00:52

标签: python animation wxpython gif

我正在尝试使用wx-Python(2.7)为gif制作动画。下面列出的代码有效但我想创建一个为我动画gif的函数,所以我可以在别处使用它。我试过在网上搜索,但我只能在__init__函数中找到动画gif的代码。有什么想法吗?

# -*- 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 个答案:

答案 0 :(得分:8)

我不明白你的问题....做这样的事情有什么问题?

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()
相关问题