【问题标题】:Is there a drag and drop function in KivyMD or Kivy?KivyMD 或 Kivy 中是否有拖放功能?
【发布时间】:2021-06-28 14:58:21
【问题描述】:

我在 Kivy 中真的很新,我想制作一个应用程序,我可以在其中创建一个可拖动的 MDIconButton,如果可能的话,可以在任何 BoxLayout 中放置?这在 KivyMD 或 Kivy 中是否可行?还有一个 Kivy 功能​​,每当我按住一个按钮时,它都会显示某种包含用户可以输入的详细信息的小对话框。谢谢!

【问题讨论】:

标签: python android kivy kivymd


【解决方案1】:

不要使用来自 kivy-garden 的 Drag-N-Drop 而是使用 DragBehavior 类!它直接与 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()

【讨论】:

    猜你喜欢
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多