0

I have a lot of questions...)

I'm trying to get Kivy to register a double tap as the motion event used to add/remove a widget [ since there is no 'hide this widget option'... maybe in the next update] because a single touch down makes the widget appear and disappear and appear and disappear over and over again (which is annoying).

My code (the important bits) [Python, followed by 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 

Kivy:

FloatLayout:
    on_touch_down:
        on_touch_down(nameofwidget)

It is giving a 'KeyError: "is_double_tap"'.

I have also tried this collection of solutions.

is_double_tap: 
    self.on_touch_down

>>> KeyError: "is_double_tap"

Another solution -

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

>>> invalid syntax [ at try:]

Another solution:

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

I think it is important to include that

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

with no definition of the on_touch_down function on the Python side, works just fine.

Misha Stone
  • 631
  • 7
  • 22

1 Answers1

0
class SomeScreen(Screen):
    def on_touch_down(touch, *args): 

This is a method, your problem is you're missing the implicit self. Declare it instead as def on_touch_down(self, touch):.

FloatLayout:
    on_touch_down:
        on_touch_down(nameofwidget)

I don't think this will work (just crash), because on_touch_down is not a defined variable.

inclement
  • 29,124
  • 4
  • 48
  • 60