您必须将以下内容添加到您的程序中。我还提供了一个示例供您参考。
animation1.bind(on_complete=animation_complete)
函数动画_完成
您的计划
def on_button_clickedBIG(self):
myLayout.CokkieAnzahl += 1
print(myLayout.CokkieAnzahl)
self.ids.CokkieZahl.text = str(myLayout.CokkieAnzahl)
anim1 = Animation(size=(650,350), duration=0.3)
anim1.bind(on_complete=self.animation_complete)
anim1.start(self.ids.CookieImage)
def animation_complete(self, widget, item):
self.remove_widget(item)
self.on_button_clickedSMALL()
def on_button_clickedSMALL(self):
anim2 = Animation(size=(600, 300))
anim2.start(self.ids.CookieImage)
程序示例
动画.py
>
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.animation import Animation
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.properties import NumericProperty
class AnimateRecord(FloatLayout):
angle = NumericProperty(0)
def __init__(self, **kwargs):
super(AnimateRecord, self).__init__(**kwargs)
animation_record = Animation(angle=360, duration=2)
animation_record += Animation(angle=360, duration=2)
animation_record.repeat = True
animation_record.start(self)
def on_angle(self, item, angle):
if angle == 360:
item.angle = 0
class AnimateButton(FloatLayout):
def animate_button(self, instance):
# create an animation object. This object could be stored
# and reused each call or reused across different widgets.
# += is a sequential step, while &= is in parallel
animation_btn = Animation(pos=(100, 100), t='out_bounce')
animation_btn += Animation(pos=(200, 100), t='out_bounce')
animation_btn &= Animation(size=(500, 500))
animation_btn += Animation(size=(100, 50))
animation_btn.bind(on_complete=self.animation_complete)
# apply the animation on the button, passed in the "instance" argument
# Notice that default 'click' animation (changing the button
# color while the mouse is down) is unchanged.
animation_btn.start(instance)
def animation_complete(self, widget, item):
self.remove_widget(item)
self.add_widget(AnimateRecord())
class AnimationsApp(App):
def build(self):
layout = AnimateButton()
# create a button, and attach animate() method as a on_press handler
button = Button(size_hint=(None, None), text='plop',
on_press=layout.animate_button)
layout.add_widget(button)
return layout
if __name__ == '__main__':
AnimationsApp().run()
动画.kv
#:kivy 1.10.0
<AnimateRecord>:
# Describe the record's position and size here
size_hint: None, None
size: 200, 200
pos_hint: {'top': 0.7, 'right': 1.1}
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: (0, 0, 1)
origin: root.center
canvas.after:
PopMatrix
Image:
source: '/home/iam/Pictures/Images/45rpm.png'
size_hint: None, None
# size: 200, 200
size: self.parent.size # So we don't have to change it every time, change the size above only
pos_hint: {'center_x': 0.5, 'center_y': 0.5}