Python 3 & Kivy:仅对双击做出反应 "not" 单击

Python 3 & Kivy: React only to double tap "not" single tap

我希望你们在这个陌生的时代都过得很好。

我有一个问题在 4 years and 6 years ago 之前被问过,但线程中的答案都没有用(至少对我而言),所以希望在过去几年中取得一些进展,我还得再问。

当使用 Python 3.8.2 和 Kivy 2.0.0 和 运行 下面的代码(我机器上的工作片段)时,在 double-clicking/double-tapping 小部件上,单击和双击寄存器。

如何以仅注册单击或仅注册双击的方式编写此代码?我只是不想同时想要两者(我实际上不确定,为什么 out-of-the-box 行为是可取的...)

如果它很重要,我在 Windows 10 上使用 anaconda,但我稍后会将此代码移植到 Raspbian。

非常感谢,伙计们。非常感谢您的意见,祝大家身体健康:)

#!/usr/bin/env python

import kivy
kivy.require('2.0.0')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class RootWidget(BoxLayout):

    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)

    def on_touch_down(self, touch):
        if touch.is_double_tap:
            print("Double Hello!")
        else:
            print("Single Hello!")

class TestApp(App):

    def build(self):
        root = RootWidget()
        return root


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

像这样:

scheduled_event = None
def on_touch_down(self, touch):
    if self.scheduled_event is not None:
            self.scheduled_event.cancel()
            self.scheduled_event = None
    if touch.is_double_tap:
            do_your_double_tap_thing()
    else:
        double_tap_wait_s = 1
        self.scheduled_event = Clock.schedule_once(do_your_single_tap_thing, double_tap_wait_s)