How to swipe left and right in python kivy app?

Viewed 2988

I want to add a swipe event in my kivy app and in my knowledge kivy does not have an event such as on_touch_left or on_touch_right available but it have another on_touch_move function which I think can be used for this purpose

class TestWidget(BoxLayout):
    def on_touch_move(self, touch):
        print touch.x

What I noticed in the above code is that if we swipe towards right touch.x value increases and if we swipe right touch.x value decreases. We just have to take the difference between the first and last touch.x value to predict left/right swipe.

The problem is how to store and retrive touch.x values from the initial to final.

3 Answers
def on_touch_move(self,touch):
    if touch.dx > 0:
        self.ids.scrn_mnger.transition.direction = 'right'
        self.ids.scrn_mnger.current = 'scrn_open'
    elif touch.dx < 0:
        self.ids.scrn_mnger.transition.direction = 'left'
        self.ids.scrn_mnger.current = 'scrn_media'
Related