请用python展示如何在wx.BusyInfo()显示的界面中通过AnimationCtrl, Animation函数添加gif动画
时间: 2023-06-03 19:08:13 浏览: 109
好的,以下是示例代码:
```python
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size=(300, 200))
self.Center()
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
button = wx.Button(panel, label='Show Busy Dialog')
button.Bind(wx.EVT_BUTTON, self.on_button_click)
vbox.Add(button, flag=wx.CENTER|wx.TOP|wx.BOTTOM, border=20)
panel.SetSizer(vbox)
def on_button_click(self, event):
busy = wx.BusyInfo("Performing a task...")
# Create an AnimationCtrl and load a gif file
animation = wx.Animation("loader.gif")
ctrl = wx.AnimatedCtrl(self, -1, animation)
ctrl.SetPosition((80, 70))
ctrl.Play()
long_task()
ctrl.Stop()
def long_task():
# Simulating a long task
import time
time.sleep(5)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(None, "Busy Dialog with Animation")
frame.Show()
app.MainLoop()
```
其中,`wx.Animation()` 用于加载 gif 文件,`wx.AnimatedCtrl()` 用于创建 animation 控件。在长时间的任务运行期间,gif 动画会一直播放,直到任务执行完毕,然后停止播放。
阅读全文