Skip to content

Instantly share code, notes, and snippets.

@Dirk-Sandberg
Created May 6, 2019 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dirk-Sandberg/32b30a738e84bcc2e828b13ca3247f4b to your computer and use it in GitHub Desktop.
Save Dirk-Sandberg/32b30a738e84bcc2e828b13ca3247f4b to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.animation import Animation
# Expands an element in a grid and adds a widget to it/
kv = """
<AnimatedListTile@FloatLayout>:
canvas.before:
Color:
rgb: 1,1,1
Rectangle:
size: self.size
pos: self.pos
animated: False
Label:
text: "Hello"
color: (0,0,0,1)
size_hint: 1, 1 if not root.animated else .5
pos_hint: {"top": 1, "right": 1}
Button:
text: "A button"
size_hint: 1, .5
pos_hint: {"top": .5, "right": 1 if root.animated else 100}
GridLayout:
cols: 1
spacing: 10,
padding: 10,
AnimatedListTile:
size_hint: 1, .1
pos_hint: {"center_x": .5, "center_y": .5}
AnimatedListTile:
id: animated_widget
size_hint: 1, .1
pos_hint: {"center_x": .5, "center_y": .5}
AnimatedListTile:
size_hint: 1, .1
pos_hint: {"center_x": .5, "center_y": .5}
AnimatedListTile:
size_hint: 1, .1
pos_hint: {"center_x": .5, "center_y": .5}
AnimatedListTile:
size_hint: 1, .1
pos_hint: {"center_x": .5, "center_y": .5}
"""
kv = Builder.load_string(kv)
class MainApp(App):
def build(self):
return kv
def on_start(self):
Clock.schedule_interval(self.animate, 2)
def animate(self, *args):
anim = Animation(size_hint_y=.3)
anim.bind(on_complete=self.reset_anim)
self.root.ids.animated_widget.animated = True
anim.start(self.root.ids.animated_widget)
def reset_anim(self, *args):
widget = self.root.ids.animated_widget
widget.size_hint_y = .1
self.root.ids.animated_widget.animated = False
MainApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment