如何在Kivy处理按下的按钮更多时间?

时间:2016-04-12 15:46:25

标签: python-2.7 button kivy

我刚才开始使用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()

0 个答案:

没有答案