2

I was wondering if it was possible to have tween animation in wxPython. I have tried looking at all the documentation but cannot seem to spot an reference to it. An example of what I am after would be having a button fly from the bottom of the window to the top. Is there such a way?

1 Answers1

5

not exactly...

there is no magic tween function builtin to wx afaik, however you can use timers to create an update interval and animate it yourself

import wx
global btn
def updater():
    p = btn.GetPosition()
    btn.SetPosition((p[0] ,p[1] - 2))
    wx.CallLater(50,updater)
a= wx.App(redirect=False)

f = wx.Frame(None,-1,"Animation",size=(400,600))
p = wx.Panel(f,-1)
btn = wx.Button(p,-1,"Click Me",pos=(175,520))
f.Show()
wx.CallLater(50,updater) #could have used a normal timer just as easy ... maybe even easier
a.MainLoop()
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • But wx.Callafter is not a timer, is it? It just puts events in the queue list for thread safety. It will still block if the event is blocking. So moving a widget will block other gui updates while it is being done. – Renae Lider Jul 17 '15 at 23:47
  • it would not fire until the gui was idle enough .... if something else was running in the main thread and was eating all the resources forever the calllater would never actually fire (in reality this should never be the case) – Joran Beasley Jul 17 '15 at 23:58