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"
'on_touch_up()'方法有一個返回值,所以你應該處理DragBehavior.on_touch_up()的返回值。 –