【问题标题】:Kivy Double TapKivy 双击
【发布时间】:2015-01-29 05:16:31
【问题描述】:

我有很多问题...)

我正在尝试让 Kivy 将双击注册为用于添加/删除小部件的动作事件 [因为没有“隐藏此小部件选项”......也许在下一次更新中]因为一次触摸down 使小部件出现和消失,一遍又一遍地出现和消失(这很烦人)。

我的代码(重要部分)[Python,其次是 Kivy]:

class SomeScreen(Screen):
    def on_touch_down(touch, *args): 
        if touch.is_double_tap:
            try: self.add_widget(*args)
            except: self.remove_widget(*args)
    pass 

基维:

FloatLayout:
    on_touch_down:
        on_touch_down(nameofwidget)

它给出了一个'KeyError:“is_double_tap”'。

我也尝试过这一系列的解决方案。

is_double_tap: 
    self.on_touch_down

>>> KeyError: "is_double_tap"

另一种解决方案 -

on_touch_down: 
    self.touch.is_double_tap = try: self.add_widget(nameofwidget), except: self.remove_widget(nameofwidget)

>>> invalid syntax [ at try:]

另一种解决方案:

on_touch_down: 
 self.on_touch_down.is_double_tap: try [ same as above]
>>> invalid syntax [ at try:]

我认为包含它很重要

on_touch_down: 
    try: self.add_widget(nameofwidget)
    except: self.remove_widget(nameofwidget)

在 Python 端没有定义 on_touch_down 函数,工作得很好。

【问题讨论】:

    标签: python touch kivy double-click motionevent


    【解决方案1】:
    class SomeScreen(Screen):
        def on_touch_down(touch, *args): 
    

    这是一种方法,您的问题是您缺少隐含的self。将其声明为 def on_touch_down(self, touch):

    FloatLayout:
        on_touch_down:
            on_touch_down(nameofwidget)
    

    我不认为这会起作用(只是崩溃),因为on_touch_down 不是定义的变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2017-07-26
      • 1970-01-01
      相关资源
      最近更新 更多