Navi
Navi

Reputation: 1052

Difference between on touch down, up and move

As I am a little confused to know the meaning and difference between on_touch_down(), on_touch_move(), on_touch_up(). Can anyone explain me how these functions works?

Note: I have already read the documentation, still couldn't understand.

Upvotes: 0

Views: 572

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

To explain correctly I will use the following example:

from kivy.app import App
from kivy.uix.widget import Widget

class MyWidget(Widget):
    def on_touch_down(self, touch):
        print("on_touch_down")
        return super(MyWidget, self).on_touch_down(touch)

    def on_touch_move(self, touch):
        print("on_touch_move")
        return super(MyWidget, self).on_touch_move(touch)

    def on_touch_up(self, touch):
        print("on_touch_up")
        return super(MyWidget, self).on_touch_up(touch)

class MyApp(App):
    def build(self):
        return MyWidget()

if __name__ == '__main__':
    MyApp().run()

If we press with the mouse, then move it and then release it we get the following:

on_touch_down
on_touch_move
on_touch_move
on_touch_move
...
on_touch_move
on_touch_move
on_touch_move
on_touch_up

And this is precisely what is managed in these 3 events:

on_touch_down: It is called when the mouse is pressed for the first time.

on_touch_move: It is called while you move the mouse while holding down

on_touch_up: It is called when you release the mouse.

Upvotes: 2

Related Questions