drag and drop graphics in tkinter?

Diez B. Roggisch deetsNOSPAM at web.de
Tue Nov 23 14:19:23 EST 2004


> I'm looking for a way to use drag-and-dropping to pick up a graphic
> and move it from one place to another. For example, I thought I could
> get my feet wet by writing a script to represent small graphs (in the
> nodes-and-vertices sense) as collections of dots and lines onscreen.
> Moving the the dots around (while maintaining line-indicated
> connections between dots) could furnish a graphical way of
> investigating questions like planarity and isomorphism.


That's not what commonly is associated with drag-and-drop - the reason
beeing that the interesting thing about drag and drop is to create a sort
of event in the drop-target that is filled with information about _what_
has been dropped - e.g. a file location - and then act accordingly. This is
not so much about the graphical appearance, but much more about protocol
issues.

What you want is to utilize the canvas widget. It can create graphics
primitives, and there are plenty of events available so that you get
noticed when the user picks a node (presumably rendered by a circle) and
drags it around. 

I've done that years ago, and tk was quite easy to use. But as its a more
tk-specific question, I suggest you search for tk canvas examples, and
translate them to tkinter.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list