Created
February 8, 2017 10:14
-
-
Save Ou42/a157c6a7dddaa74ba1cd4f49a158fde3 to your computer and use it in GitHub Desktop.
kivy count down animation WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
count down 3-2-1 w/ fade out to full transparency | |
''' | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.label import Label | |
from kivy.properties import NumericProperty | |
from kivy.animation import Animation | |
Builder.load_string(''' | |
<CustomFloat>: | |
Button: | |
text: 'Click me to start' | |
on_press: root.start_count_down() | |
size_hint: (1,0.1) | |
<CustomLabel>: | |
font_size: '42sp' | |
size_hint: (0.75, 0.75) # (None, None) | |
pos_hint: {'center_x': 0.5, 'center_y': 0.5} | |
canvas.before: | |
Color: | |
rgba: 0.47, 0.65, 1.0, 1.0 | |
Rectangle: | |
# self here refers to ??? the widget ??? (CustomLabel?!) | |
pos: self.pos | |
size: self.size | |
''') | |
class CustomFloat(FloatLayout): | |
label_number = NumericProperty(3) | |
def start_count_down(self): | |
self.label_number = 3 | |
self.count_down() | |
def count_down(self, animation=None, widget=None): | |
my_label = CustomLabel(text=str(self.label_number), color=[1,1,1,1]) | |
self.add_widget(my_label) | |
Animation.cancel_all(my_label) | |
fade_to_color = [1,1,1,0] | |
anim = Animation(color=fade_to_color, font_size=250.0, | |
duration=1.0, t='in_circ') | |
if self.label_number > 1: | |
anim.bind(on_complete=self.count_down) | |
anim.start(my_label) | |
self.label_number -= 1 | |
class CustomLabel(Label): | |
pass | |
class TestApp(App): | |
def build(self): | |
return CustomFloat() | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment