classMoveWidget(Animation):"""Animation of moving `virtual.Widget`."""def__init__(self,widget:virtual.Widget,offset:tuple[float,float],duration:int,*,controller:collections.abc.Callable[[float],float]=controllers.linear,end:collections.abc.Callable[[],typing.Any]|None=None,fps:int=30,repeat:int=0,repeat_delay:int=0,)->None:""" * `widget`: the `virtual.Widget` to be moved * `offset`: relative offset of the coordinates * `duration`: duration of the animation, in milliseconds * `controller`: a function that controls the animation process * `end`: end function, which is called once at the end of the animation * `fps`: frame rate of the animation * `repeat`: number of repetitions of the animation * `repeat_delay`: length of the delay before the animation repeats """Animation.__init__(self,duration,lambdap:widget.move(offset[0]*p,offset[1]*p),controller=controller,end=end,fps=fps,repeat=repeat,repeat_delay=repeat_delay,derivation=True,)
importmathimportmaliangimportmaliang.animationasanimationclassMyAnimation(animation.Animation):"""My customized animation class"""def__init__(self,ms:int,window:maliang.Tk,*args,**kwargs)->None:"""Let the window gradually change from transparent to clear"""controller=animation.generate(math.sin,0,math.pi,map_y=False)super().__init__(ms,window.alpha,controller=controller,*args,**kwargs)root=maliang.Tk()MyAnimation(2000,root,repeat=-1,fps=60).start(delay=1000)root.mainloop()