目录
拖拽行为¶
: DragBehavior mixin 类提供了拖拽行为。当与一个部件结合使用时,在由 drag_rectangle 定义的矩形区域内进行拖拽将移动该部件。
示例¶
以下示例创建了一个可拖动的标签:
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)[源代码]¶
基类:
objectDragBehavior mixin 提供了拖拽行为。当与一个部件结合时,在由
drag_rectangle定义的矩形内进行拖拽将移动该部件。更多信息请参阅拖拽行为模块的文档。在 1.8.0 版本加入.
- drag_distance¶
拖动
DragBehavior之前需要移动的距离,单位为像素。一旦达到该距离,DragBehavior将开始拖动,并且不会向子组件派发触摸事件。建议您根据目标设备屏幕的 dpi 来设定此值。drag_distance是一个NumericProperty,默认值等于用户Config中定义的 `scroll_distance`(默认为 20 像素)。
- drag_rect_height¶
允许拖拽的轴对齐边界矩形的高度。
drag_rect_height是一个NumericProperty,默认值为 100。
- drag_rect_width¶
允许拖拽的轴对齐边界矩形的宽度。
drag_rect_width是一个NumericProperty,默认值为 100。
- drag_rect_x¶
允许拖动的轴对齐边界矩形的X位置(以窗口坐标表示)。
drag_rect_x是一个NumericProperty,默认值为 0。
- drag_rect_y¶
允许拖动的轴对齐边界矩形的Y坐标位置(以窗口坐标表示)。
drag_rect_Y是一个NumericProperty,默认值为 0。
- drag_rectangle¶
允许拖动的轴对齐边界矩形的位置和大小。
drag_rectangle是一个ReferenceListProperty,由 (drag_rect_x,drag_rect_y,drag_rect_width,drag_rect_height) 属性组成。
- drag_timeout¶
允许触发
drag_distance的超时时间,单位为毫秒。如果用户在此超时时间内未移动drag_distance,则拖拽将被禁用,触摸事件将分发给子组件。drag_timeout是一个NumericProperty,默认值为用户Config中定义的 `scroll_timeout`(默认55毫秒)。