簡體   English   中英

KivyMD或Kivy中是否有拖放function?

[英]Is there a drag and drop function in KivyMD or Kivy?

我在 Kivy 中真的很新,我想制作一個應用程序,我可以在其中創建一個可拖動的 MDIconButton,如果可能的話,可以在任何 BoxLayout 中放置? 這在 KivyMD 或 Kivy 中是否可行? 還有一個 Kivy function ,每當我按住一個按鈕時,它都會顯示某種包含用戶可以輸入的詳細信息的小對話框。 謝謝!

與其使用 kivy-garden 的 Drag-N-Drop,不如使用DragBehavior class。 它直接與 Kivy 一起安裝,這樣您就不必安裝 kivy-garden。

https://kivy.org/doc/stable/api-kivy.uix.behaviors.drag.html

這是一些如何使用它的示例代碼:

from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.behaviors import DragBehavior
from kivy.lang import Builder

# You could also put the following in your kv file...
kv = '''
<DragLabel>:
    # Define the properties for the DragLabel
    drag_rectangle: self.x, self.y, self.width, self.height
    drag_timeout: 10000000
    drag_distance: 0

FloatLayout:
    # Define the root widget
    DragLabel:
        size_hint: 0.25, 0.2
        text: 'Drag me'
'''


class DragLabel(DragBehavior, Label):
    pass


class TestApp(App):
    def build(self):
        return Builder.load_string(kv)

TestApp().run()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM