Touch

Provides easy access to events.

The following events are available:

  • on_long_touch

  • on_double_tap

  • on_triple_tap

Usage

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.behaviors import TouchBehavior
from kivymd.uix.button import MDRaisedButton

KV = '''
Screen:

    MyButton:
        text: "PRESS ME"
        pos_hint: {"center_x": .5, "center_y": .5}
'''


class MyButton(MDRaisedButton, TouchBehavior):
    def on_long_touch(self, *args):
        print("<on_long_touch> event")

    def on_double_tap(self, *args):
        print("<on_double_tap> event")

    def on_triple_tap(self, *args):
        print("<on_triple_tap> event")


class MainApp(MDApp):
    def build(self):
        return Builder.load_string(KV)


MainApp().run()

API - kivymd.uix.behaviors.touch_behavior

class kivymd.uix.behaviors.touch_behavior.TouchBehavior(**kwargs)
duration_long_touch

Time for a long touch.

duration_long_touch is an NumericProperty and defaults to 0.4.

create_clock(self, widget, touch, *args)
delete_clock(self, widget, touch, *args)
on_long_touch(self, touch, *args)

Called when the widget is pressed for a long time.

on_double_tap(self, touch, *args)

Called by double clicking on the widget.

on_triple_tap(self, touch, *args)

Called by triple clicking on the widget.