Skip to content

Instantly share code, notes, and snippets.

@kived
Created October 6, 2014 18:22
Show Gist options
  • Save kived/711a4e66c1f6e5cbe81c to your computer and use it in GitHub Desktop.
Save kived/711a4e66c1f6e5cbe81c to your computer and use it in GitHub Desktop.
Kivy: increment/decrement for 1.8.0
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.properties import NumericProperty
class TestApp(App):
value = NumericProperty(0)
def build(self):
return Builder.load_string('''
BoxLayout:
orientation: 'vertical'
Label:
text: str(app.value)
canvas.before:
Color:
rgba: app.value / 64., (64 - app.value) / 64., 0, 1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
Button:
text: '-'
on_press: app.minus()
on_release: app.stopupdate()
Button:
text: '+'
on_press: app.plus()
on_release: app.stopupdate()
''')
def _do_plus(self, dt):
self.value += 1
def _do_minus(self, dt):
self.value -= 1
def plus(self):
self.event = self._do_plus
Clock.schedule_interval(self._do_plus, 0.1)
self._do_plus(None)
def minus(self):
self.event = self._do_minus
Clock.schedule_interval(self._do_minus, 0.1)
self._do_minus(None)
def stopupdate(self):
Clock.unschedule(self.event)
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment