drag and drop graphics in tkinter?

S

Sean McIlroy

The subject line essentially says it all. Is there a way to do it? If
so, where do I look to find out how? Any help will be much
appreciated.

Thx,
STM
 
E

Eric Brunel

Sean said:
The subject line essentially says it all. Is there a way to do it? If
so, where do I look to find out how? Any help will be much
appreciated.

Thx,
STM

I'm not quite sure I understand your question: drag and drop between what and
what? Two windows in a Tkinter application? A file manager and a Tkinter
application?

If you want to support drag and drop inside a Tkinter application, check the
file Tkdnd.py in the Lib/lib-tk sub-directory of the source Python distribution.

HTH
 
S

Sean McIlroy

Eric Brunel said:
I'm not quite sure I understand your question: drag and drop between what and
what?

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.
 
S

Sean McIlroy

Eric Brunel said:
I'm not quite sure I understand your question: drag and drop between what and
what?

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.
 
D

Diez B. Roggisch

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.
 
L

Lonnie Princehouse

I'm looking for a way to use drag-and-dropping to pick up a graphic
Yep, the canvas widget is the way to go. You might also take a look
at wxPython instead of Tkinter -- if I recall correctly, there's some
kind of graph widget that might save you some time (run the demo.py
script to find it). Also, as someone who has spent a lot of time
lately tinkering with graphs, I can highly recommend graphviz. If you
haven't already looked at it, it's an excellent tool for graph layout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top