2017-12-03 134 views
0

当我使用Drag_GiveImage类(继承了DragBehavior和Image的类)和on_touch_up时,一旦我拖放图像,就无法拖动图像。DragBehavior第一次只能在基维的on_touch_up上工作

我不知道为什么会发生这种情况以及如何解决。

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" 

回答

0

在你on_touch_up()方法,你应该因为你是在覆盖的DragBehavior方法on_touch_up()添加一个调用

super(DraggableImage,self).on_touch_up(touch) 

+0

'on_touch_up()'方法有一个返回值,所以你应该处理DragBehavior.on_touch_up()的返回值。 –