Skip to content

Instantly share code, notes, and snippets.

@quapka
Last active August 29, 2015 14:07
Show Gist options
  • Save quapka/3cda51bc8f8ea794287b to your computer and use it in GitHub Desktop.
Save quapka/3cda51bc8f8ea794287b to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.animation import Animation
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.graphics.vertex_instructions import Rectangle
from kivy.graphics.context_instructions import Color
from kivy.lang import Builder
from kivy.clock import ClockBase, Clock
from kivy.properties import ListProperty
from numpy import array
class ScoreApp(App):
def build(self):
return MyBoxLayout()
class MyBoxLayout(BoxLayout):
def increase_score(self, *args):
self.event = Clock.schedule_interval(self.clock_increase_score, .2)
#self.event()
def clock_increase_score(self, *args):
self.ids.score_label.color_grad[0] -= .01
self.ids.score_label.color_grad[1] += .01
self.ids.score_label.text = str(int(self.ids.score_label.text) + 1)
def shut_increase_score(self, *args):
self.event.cancel()
class ScoreLabel(Label):
color_grad = ListProperty([1,0,0,1])
class MyButton(Button):
def on_touch_down(self, touch):
pass
Builder.load_string('''
<MyBoxLayout>:
Button:
text: '+'
font_size: 100
on_press: root.increase_score()
on_release: root.shut_increase_score()
ScoreLabel:
id: score_label
color_grad: 1,0,0,1
text: '0'
font_size: 100
canvas.before:
Color:
rgba: self.color_grad
Rectangle:
pos: self.pos
size: self.size
Button:
text: '-'
font_size: 100
''')
ScoreApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment