Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created May 16, 2012 20:52
Show Gist options
  • Save tshirtman/2713864 to your computer and use it in GitHub Desktop.
Save tshirtman/2713864 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from kivy.app import App
from kivy.animation import Animation
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
class TestB(App):
def build(self):
self.f = FloatLayout()
self.ti = TextInput(
pos_hint={'top': 1},
size_hint=(1, None),
multiline=False,
text='1')
self.b = Button(size_hint=(None, None))
self.b.bind(on_press=self.moveit)
self.f.add_widget(self.ti)
self.f.add_widget(self.b)
return self.f
def moveit(self, *args):
try:
duration = float(self.ti.text)
if duration <= 0:
raise ValueError
a = Animation(x=self.f.right, d=duration)
a += Animation(x=0, d=duration)
a.start(self.b)
except ValueError:
self.ti.text = 'please put a valid positive float number'
if __name__ == '__main__':
TestB().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment