繁体   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