我刚才开始使用Kivy。我想对按钮做出反应,就像on_key_down一样。有什么可能的,或者做得对吗?
from kivy.app import App
from kivy.uix.button import Button
from kivy.clock import Clock
class MyApp(App):
def build(self):
self.button = Button(text='Button', size_hint=(1, None))
# When button is up
self.button.bind(on_release=self.on_release)
# When button is pressed
self.button.bind(on_press=self.on_press)
# Call update every n seconds
Clock.schedule_interval(self.update, 1.0/10.01)
return self.button
def on_release(self, *args):
print self.button.state
def on_press(self, *args):
print self.button.state
def update(self, dt):
if self.button.state == 'down':
print 'move', dt
if __name__ == '__main__':
MyApp().run()