Python Kivy在按下时vs在触地时

Python Kivy在按下时vs在触地时,python,python-3.x,kivy,kivy-language,Python,Python 3.x,Kivy,Kivy Language,我有一个Kivy标签上的数字和两个按钮,一个增加该数字,一个减少该数字。我惊讶地发现,当使用on_touch_down时,+按钮不起作用。我注释掉了-按钮,然后+按钮开始工作 我将on_touch_down更改为on_press,两个按钮都存在/功能协调 有人能告诉我为什么吗 下面是一个.py文件示例: from kivy.app import App from kivy.uix.boxlayout import BoxLayout class Counter(BoxLayout):

我有一个Kivy标签上的数字和两个按钮,一个增加该数字,一个减少该数字。我惊讶地发现,当使用on_touch_down时,+按钮不起作用。我注释掉了-按钮,然后+按钮开始工作

我将on_touch_down更改为on_press,两个按钮都存在/功能协调

有人能告诉我为什么吗

下面是一个.py文件示例:

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


class Counter(BoxLayout):

    def count_up(self):
        value = self.ids.the_number.text
        self.ids.the_number.text = str(int(value) + 1)

    def count_down(self):
        value = self.ids.the_number.text
        self.ids.the_number.text = str(int(value) - 1)


class ProofApp(App):
    def build(self):
        return Counter()


if __name__ == '__main__':
    ProofApp().run()
和.kv文件:

<Counter>:
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'top'

        BoxLayout:
            orientation: 'horizontal'

            BoxLayout:

                Label:
                    id: the_number
                    text: "1"

            BoxLayout:
                orientation: 'vertical'
                padding: 2

                Button:
                    id: count_up
                    text: "+"
                    on_press: root.count_up()

                Button:
                    id: count_down
                    text: "-"
                    on_press: root.count_down()

on_touch_down启动小部件树中的所有内容。你的按钮相互抵消了


如果您的按钮正在执行其他操作,这些操作不会相互抵消,那么您将看到两个操作都会启动。例如,如果一个按钮打印了hello和一个打印的world,那么按下似乎不起作用的按钮将打印hello world。

on\u touch\u down触发小部件树中的所有内容。你的按钮相互抵消了

如果您的按钮正在执行其他操作,这些操作不会相互抵消,那么您将看到两个操作都会启动。例如,如果一个按钮打印了hello和一个打印的world,则按下似乎不起作用的按钮将打印hello world。

where is on_touch_down?它们取代了.kv文件中的on_press事件。where is on_touch_down?它们取代了.kv文件中的on_press事件。