2017-12-03 105 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()的返回值。 –