Skip to content

Instantly share code, notes, and snippets.

@el3
Last active May 10, 2019 12:50
Show Gist options
  • Save el3/a6b6344dba2cf0a1feb9338f17aedf48 to your computer and use it in GitHub Desktop.
Save el3/a6b6344dba2cf0a1feb9338f17aedf48 to your computer and use it in GitHub Desktop.
boxlayout_animation
from kivy.lang import Builder
from kivy.app import App
from kivy.animation import Animation
class MyAnim(Animation):
def on_complete(self, widget):
widget.expanded = not widget.expanded
if not widget.expanded:
widget.size_hint = (1,1)
KV = """
<MyButton@Button>:
font_size: "30sp"
expanded: False
on_release:
self.size_hint = (None, 1)
anim = app.anim(width=self.parent.width/3 if self.expanded else self.parent.width)
anim.start(self)
BoxLayout:
MyButton:
text: "test1" if self.width > 10 else ""
MyButton:
text: "test2" if self.width > 10 else ""
MyButton:
text: "test3" if self.width > 10 else ""
"""
class MyApp(App):
anim = MyAnim
def build(self):
return Builder.load_string(KV)
MyApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment