Table Of Contents
Drag Behavior¶
The DragBehavior
mixin class provides Drag behavior.
When combined with a widget, dragging in the rectangle defined by the
drag_rectangle
will drag the
widget.
Example¶
The following example creates a draggable label:
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()
-
class
kivy.uix.behaviors.drag.
DragBehavior
(**kwargs)[ソース]¶ ベースクラス:
builtins.object
The DragBehavior mixin provides Drag behavior. When combined with a widget, dragging in the rectangle defined by
drag_rectangle
will drag the widget. Please see thedrag behaviors module
documentation for more information.バージョン 1.8.0 で追加.
-
drag_distance
¶ Distance to move before dragging the
DragBehavior
, in pixels. As soon as the distance has been traveled, theDragBehavior
will start to drag, and no touch event will be dispatched to the children. It is advisable that you base this value on the dpi of your target device’s screen.drag_distance
is aNumericProperty
and defaults to the scroll_distance as defined in the userConfig
(20 pixels by default).
-
drag_rect_height
¶ Height of the axis aligned bounding rectangle where dragging is allowed.
drag_rect_height
is aNumericProperty
and defaults to 100.
-
drag_rect_width
¶ Width of the axis aligned bounding rectangle where dragging is allowed.
drag_rect_width
is aNumericProperty
and defaults to 100.
-
drag_rect_x
¶ X position of the axis aligned bounding rectangle where dragging is allowed (in window coordinates).
drag_rect_x
is aNumericProperty
and defaults to 0.
-
drag_rect_y
¶ Y position of the axis aligned bounding rectangle where dragging is allowed (in window coordinates).
drag_rect_Y
is aNumericProperty
and defaults to 0.
-
drag_rectangle
¶ Position and size of the axis aligned bounding rectangle where dragging is allowed.
drag_rectangle
is aReferenceListProperty
of (drag_rect_x
,drag_rect_y
,drag_rect_width
,drag_rect_height
) properties.
-
drag_timeout
¶ Timeout allowed to trigger the
drag_distance
, in milliseconds. If the user has not moveddrag_distance
within the timeout, dragging will be disabled, and the touch event will be dispatched to the children.drag_timeout
is aNumericProperty
and defaults to the scroll_timeout as defined in the userConfig
(55 milliseconds by default).
-