【发布时间】:2023-11-01 00:52:01
【问题描述】:
下面的代码应该在单击一个按钮时播放一些 gif 图像..并在单击另一个按钮时播放另一个 gif 图像.. 但是当我单击第一个按钮时,它正在正确播放相关图像.. 而通过单击第二个按钮,第一个图像和第二个图像都在无限循环中一个接一个地播放 ...那么如何通过按钮单击播放一个 gif?
import wx, wx.animate
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY)
panel = wx.Panel(self, wx.ID_ANY)
btn1 = wx.Button(self, -1, "play GIF 1",(50,10))
btn1.Bind(wx.EVT_BUTTON, self.onButton1)
btn2 = wx.Button(self, -1, "play GIF 2",(50,40))
btn2.Bind(wx.EVT_BUTTON, self.onButton2)
#----------------------------------------------------------------------
def onButton1(self, event):
image='animated_1.gif'
self.animateGIF(image)
#----------------------------------------------------------------------
def onButton2(self, event):
image='animated_2.gif'
self.animateGIF(image)
#----------------------------------------------------------------------
def animateGIF(self,image):
gif = wx.animate.GIFAnimationCtrl(self, -1, image,pos=(50,70),size=(10,10))
gif.GetPlayer()
gif.Play()
#----------------------------------------------------------------------
app = wx.App()
frame = MyForm().Show()
app.MainLoop()
【问题讨论】:
标签: python python-2.7 wxpython