DragBehavior lost when moving widget after creation

12 views
Skip to first unread message

Frédéric

unread,
Jul 8, 2024, 2:03:15 PM (8 days ago) Jul 8
to Kivy users support
Hello!

Il I change the position of a  a widget from python, the DragBehavior isn't working anymore.

How can I recover the dragbehavior after changing position?

Here's an exemple showing the non-draggable widget. Without the on_start function, it's draggable

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:
    DragLabel:
        id:drag
        size_hint: 0.25, 0.2
        text: 'Drag me'
'''


class DragLabel(DragBehavior, Label):
    pass


class TestApp(App):
    def on_start(self, **kwargs):
        self.root.ids.drag.pos_hint = {"x":0.5, "y":0.5}
       
    def build(self):
        return Builder.load_string(kv)
       

TestApp().run()

ELLIOT GARBUS

unread,
Jul 8, 2024, 3:50:19 PM (8 days ago) Jul 8
to Kivy users support
Do not use a pos_hint to set the position.  The pos_hint is "overriding" drag.

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Frédéric <freder...@gmail.com>
Sent: Monday, July 8, 2024 11:03 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] DragBehavior lost when moving widget after creation
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2ce3b2ca-4a76-476b-b10e-5d84d0f30ec8n%40googlegroups.com.

Frédéric

unread,
Jul 8, 2024, 4:04:34 PM (8 days ago) Jul 8
to Kivy users support
OK,

I'll change my code to use pos instead of pos_hint
Thanks!

Frederic

Reply all
Reply to author
Forward
0 new messages