Lagyu
Lagyu

Reputation: 127

DragBehavior only work for the first time with on_touch_up in Kivy

When I use DraggableImage class (a class which inherits DragBehavior and Image) with on_touch_up, once I dragged and dropped a image, the image cannot be dragged anymore.

I don't know why this happens and how to fix.

from kivy.app import App
from kivy.uix.behaviors import DragBehavior
from kivy.uix.image import Image

class DraggableImage(DragBehavior, Image):
    def on_touch_up(self, touch):  # without this (e.g. "pass" here), image is always draggable.
        print("This is test")

class TestApp(App):
    def build(self):
        pass

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

test.kv

BoxLayout:
    DraggableImage:
        source: "example.png"

Upvotes: 1

Views: 103

Answers (1)

John Anderson
John Anderson

Reputation: 39117

In your on_touch_up() method, you should add a call to

super(DraggableImage,self).on_touch_up(touch)

since you are overriding the on_touch_up() method in DragBehavior.

Upvotes: 1

Related Questions