简体   繁体   English

KivyMD或Kivy中是否有拖放function?

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

im really new in Kivy and i would like to make an app where i could create a MDIconButton that is draggable, and if possible, droppable in any BoxLayout?我在 Kivy 中真的很新,我想制作一个应用程序,我可以在其中创建一个可拖动的 MDIconButton,如果可能的话,可以在任何 BoxLayout 中放置? Is that possible in KivyMD or Kivy?这在 KivyMD 或 Kivy 中是否可行? Also is there a Kivy function where whenever I hold down a button, it'll display some kind of small dialogue box that contains details that can be entered by the user.还有一个 Kivy function ,每当我按住一个按钮时,它都会显示某种包含用户可以输入的详细信息的小对话框。 thanks!谢谢!

Rather than use Drag-N-Drop from kivy-garden just use the DragBehavior class.与其使用 kivy-garden 的 Drag-N-Drop,不如使用DragBehavior class。 It comes directly installed with Kivy and it'll save you having to install kivy-garden.它直接与 Kivy 一起安装,这样您就不必安装 kivy-garden。

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

Here is some example code of how it's used:这是一些如何使用它的示例代码:

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