简体   繁体   English

Kivy拖放区太大

[英]Kivy drag n drop area is too big

Reposting this with example code from geeksforgeeks.使用来自 geeksforgeeks 的示例代码重新发布此内容。 I am testing a simple drag and drop function in Kivy with the Drag Behavior module:我正在使用 Drag Behavior 模块在 Kivy 中测试一个简单的拖放 function:

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

However, I can't seem to work out how to make the draggable area small.但是,我似乎无法弄清楚如何使可拖动区域变小。 I've tried playing around with the numbers on the drag_rectangle parameters, but the draggable area either doesn't get smaller or just completely disappears for some reason (meaning I can't drag the square).我尝试过使用 drag_rectangle 参数上的数字,但可拖动区域要么不会变小,要么由于某种原因完全消失(这意味着我不能拖动正方形)。 For reference, this is the issue:供参考,这是问题:

在此处输入图像描述

If you run the code in this geeksforgeeks sample the same problem happens so I think it has to something to do with the module itself: https://www.geeksforgeeks.org/how-to-add-drag-behavior-in-kivy-widget/如果您在此 geeksforgeeks 示例中运行代码,则会发生相同的问题,因此我认为这与模块本身有关: https://www.geeksforgeeks.org/how-to-add-drag-behavior-in-kivy -小部件/

Refering the link you provided .参考您提供的链接

The drag behavior is applied to the widget (here, Label ) which is triggered when the touch is within drag_rectangle (default position is (0, 0)).拖动行为应用于小部件(此处为Label ),当触摸在drag_rectangle内时触发(默认 position 为 (0, 0))。 Here this is defined to be the whole widget ( drag_rectangle: self.x, self.y, self.width, self.height ).这里定义为整个小部件( drag_rectangle: self.x, self.y, self.width, self.height )。

However, I can't seem to work out how to make the draggable area small...但是,我似乎无法弄清楚如何使可拖动区域变小......

I think that can be achieved either by restricting the drag rectangle by something like,我认为这可以通过限制拖动矩形来实现,例如,

drag_rectangle: self.center_x - dp(100), self.center_y - dp(100), dp(200), dp(200) # Within a square of length dp(100) centered at widget's center.

Or by limiting the appearance (physical boundary) of the widget using size/size_hint,或者通过使用 size/size_hint 限制小部件的外观(物理边界),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM