[python-win32] Drag and Drop issues

Mike Driscoll mdriscoll at co.marshall.ia.us
Tue Apr 22 19:41:56 CEST 2008


Alex Denham wrote:
> Hi,
>
> I'm trying to implement a drag and drop feature in my Tkinter based gui.
> I want to be able to drag a file from windows (explorer/desktop etc) 
> into my program. Then i need my program to get the filepath for the 
> file that was dropped.
>
> I've tried to search all over the internet, in books and in the win32 
> documentation provided with the win32 package but i keep finding 
> conflicting information.
>
> Furthest i have gotten is the following:
>
>     _id = root.winfo_id()
>     win32gui.DragAcceptFiles(_id, 1)
>
> That works, without that i don't get the little 'drop' icon  when i 
> drag something over, however after that i'm completly stuck, i've 
> tried using win32gui.GetMessage() to see if there is anything in that 
> output that relates to a drop,
> I've tried win32api.DragQueryFile(_id).
>
> I think i need to do something using a PyIDropTarget but i have no 
> idea where to import that from, i've tried making a class with that as 
> the name and then initializing it and passing it to 
> pythoncom.RegisterDragDrop(_id, dropTarget)
> dropTarget being the initialized PyIDropTarget class, however it says, 
> it's not a com object...
>
> I think i've just managed to get myself confused, i just need a 
> pointer on the right way to do it, do i use registerdrag drop or do i 
> use dragqueryfile and dragacceptfiles, and how to i check to see if my 
> program has recieved a drop request, is there some sort of event or 
> something i can listen for (thats initially what i thought 
> GetMessage() was for but i'm unsure how to use it)
>
> Any help would be much appreciated.
> And if you need any more info don't hesitate to ask.
>
> Thanks in advance
> Alex
I did a quick Google search and found this: 
http://sourceforge.net/projects/tkdnd

Alternatively, I know wxPython has DnD capabilities of sorts too, so if 
you can't get it in Tkinter, you might check it out there. By the way, 
did you try asking for help on the Tkinter mailing list? If not, you can 
find it here: http://mail.python.org/mailman/listinfo/tkinter-discuss

Mike



More information about the python-win32 mailing list