You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch improves two things I always found annoying
with Tkdnd.
First, it is not possible to change the default cursor
("hand2") that is used for drag and drop operations,
second, this cursor always shows up on <ButtonPress>
events and not on <Motion> events, as I think it should.
This has the ugly effect that if for example you use
Tkdnd to drag items from a Listbox, each time the user
selects a new item from the Listbox, the "hand2" cursor
pops up.
To fix the first issue I added a "dndcursor" option to
the dnd_start() function, which defaults to "hand2" to
keep the "classic" behavior intact.
Second I added a self.dndcursor attribute to the
DnDHandler class that stores this dndcursor's value;
then I moved the call that actually changes the
widget's cursor into the DnDHandler.on_motion() method
to make sure that this cursor only shows when actually
some drag occurs. self.dndcursor is set to None then,
to avoid multiple calls to "widget['cursor'] == ...". I
know that this is a slight change to the original
behavior, however I doubt that anyone will miss it.
I just created a sample listbox with drag & drop support and it indeed
looks better if the "hand2" cursor or whatever cursor is set only shows
up when motion starts. But, for the sample included with Tkdnd, I find
it better to show up the different cursor when clicking the canvas item
instead of waiting to starting move it.
Are you willing to adjust that ?
The first feature added -- to support custom cursor is fine, just this
second change needs to be rethought.
Maybe this depends on whether the dragged item is "clickable" like
listbox items and buttons or not , like the Labels in the Tkdnd demo.
Ok, I wrote a second patch that solves this by adding another option to
dnd_start(); if this option is set to True (the default) the user gets
the classic behavior, if set to False the cursor changes when the motion
starts, as in the initial patch. I couldn't figure out a good name for
this option, so I called it "swapcursoronclick", at least the name says
what it is for ^_^
#152371 fixes the cursor flash on a plain click: the drag cursor is now deferred until the pointer moves past a small threshold, matching BWidget's drag-and-drop.
Leaving this open for the configurable-cursor question. Note that an application can already show its own cursor from the drop-target callbacks, e.g.:
defdnd_enter(self, source, event):
self.widget['cursor'] ='plus'# show a custom drop cursor
...
defdnd_leave(self, source, event):
self.widget['cursor'] =''# restore it
...
Activity
klappnase commentedon Jul 20, 2006
This patch improves two things I always found annoying
with Tkdnd.
First, it is not possible to change the default cursor
("hand2") that is used for drag and drop operations,
second, this cursor always shows up on <ButtonPress>
events and not on <Motion> events, as I think it should.
This has the ugly effect that if for example you use
Tkdnd to drag items from a Listbox, each time the user
selects a new item from the Listbox, the "hand2" cursor
pops up.
To fix the first issue I added a "dndcursor" option to
the dnd_start() function, which defaults to "hand2" to
keep the "classic" behavior intact.
Second I added a self.dndcursor attribute to the
DnDHandler class that stores this dndcursor's value;
then I moved the call that actually changes the
widget's cursor into the DnDHandler.on_motion() method
to make sure that this cursor only shows when actually
some drag occurs. self.dndcursor is set to None then,
to avoid multiple calls to "widget['cursor'] == ...". I
know that this is a slight change to the original
behavior, however I doubt that anyone will miss it.
Regards
Michael
gpolo commentedon Apr 23, 2009
I just created a sample listbox with drag & drop support and it indeed
looks better if the "hand2" cursor or whatever cursor is set only shows
up when motion starts. But, for the sample included with Tkdnd, I find
it better to show up the different cursor when clicking the canvas item
instead of waiting to starting move it.
Are you willing to adjust that ?
The first feature added -- to support custom cursor is fine, just this
second change needs to be rethought.
klappnase commentedon Apr 23, 2009
Maybe this depends on whether the dragged item is "clickable" like
listbox items and buttons or not , like the Labels in the Tkdnd demo.
Ok, I wrote a second patch that solves this by adding another option to
dnd_start(); if this option is set to True (the default) the user gets
the classic behavior, if set to False the cursor changes when the motion
starts, as in the initial patch. I couldn't figure out a good name for
this option, so I called it "swapcursoronclick", at least the name says
what it is for ^_^
gh-43699: Defer the drag cursor in tkinter.dnd until the pointer moves (
serhiy-storchaka commentedon Jul 5, 2026
#152371 fixes the cursor flash on a plain click: the drag cursor is now deferred until the pointer moves past a small threshold, matching BWidget's drag-and-drop.
Leaving this open for the configurable-cursor question. Note that an application can already show its own cursor from the drop-target callbacks, e.g.: