【发布时间】:2017-11-26 18:59:17
【问题描述】:
我在一个特定的想法上遇到了麻烦:
我创建了一个可以使用 Kivy 中的拖动行为拖动的矩形。虽然,我希望只向左/向右拖动矩形并固定 Y 位置。
我怎样才能做到这一点?我尝试了多种组合,在网上寻找这个特定的问题,我什至检查了源代码,但我无法把它放在一起。非常感谢您的帮助!
下面是代码:
from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.behaviors import DragBehavior
from kivy.lang import Builder
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: 1.0, 0.2
text: 'Drag me'
canvas.before:
Color:
rgb: .6, .6, .6
Rectangle:
pos: self.pos
size: self.size
'''
class DragLabel(DragBehavior, Label):
pass
class RectangleApp(App):
def build(self):
object = Builder.load_string(kv)
return object
if __name__ == '__main__':
RectangleApp().run()
【问题讨论】:
标签: python python-2.7 kivy kivy-language