Repository navigation
Tkdnd mouse cursor handling patch #43699
Description
Activity
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
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 30, 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.- addedtype-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on 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 ^_^- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 23, 2023 - added a commit that references this issue
on Jul 5, 2026 - added3.16new features, bugs and security fixesnew features, bugs and security fixesand removed3.10 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on 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.:
def dnd_enter(self, source, event): self.widget['cursor'] = 'plus' # show a custom drop cursor ... def dnd_leave(self, source, event): self.widget['cursor'] = '' # restore it ...
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs