1

I installed TkDnD as instructed here: How to Install and Use TkDnD with Python 2.7 Tkinter on OSX?

Mainly i followed this advice:

On Windows:

1) Copy the tkdnd2.8 directory to C:\Python27\tcl

2) Copy the TkinterDnD2 directory to C:\Python27\Lib\site-packages

I am using anaconda so I copied it into my environments directories (C:\ProgramData\Anaconda3\envs\gui)

And yet when i try to run this code:

import sys
if sys.version_info[0] == 2:
    from Tkinter import *
else:
    from tkinter import *
from TkinterDnD2 import *

def drop(event):
    entry_sv.set(event.data)

root = TkinterDnD.Tk()
entry_sv = StringVar()
entry_sv.set('Drop Here...')
entry = Entry(root, textvar=entry_sv, width=80)
entry.pack(fill=X, padx=10, pady=10)
entry.drop_target_register(DND_FILES)
entry.dnd_bind('<<Drop>>', drop)
root.mainloop()

I get this error

Exception has occurred: RuntimeError
Unable to load tkdnd library.
  File "drag_and_drop_GUI.py", line 10, in <module>
    root = TkinterDnD.Tk()

Thinking it's a problem with anaconda I installed TkDnD in my system Python too (no virtual environments) but the issue still persists. Any ideas ?

Luke Kuc
  • 13
  • 1
  • 4
  • Are you sure you installed the library in your anaconda python installation? I thought the Anaconda interpreter and basic interpreter were separate? – NoSplitSherlock Mar 07 '19 at 13:40
  • Im pretty sure, I installed those 2 elements in these directories: C:\ProgramData\Anaconda3\envs\gui\tcl\tkdnd2.8 C:\ProgramData\Anaconda3\envs\gui\Lib\site-packages\TkinterDnD2 I just called my env gui. They are separate but I just installed Python that is separate from anaconda to check if conda is the problem. – Luke Kuc Mar 07 '19 at 13:43
  • Wait a second, you're importing FROM TkinterDnD2, what happens if you just instantiate Tk() instead of TkinterDnD2.Tk()? – NoSplitSherlock Mar 07 '19 at 13:48
  • I get a different error on a later line entry.drop_target_register(DND_FILES) Exception has occurred: _tkinter.TclError invalid command name "tkdnd::drop_target" File "drag_and_drop_GUI.py", line 16, in entry.drop_target_register(DND_FILES) – Luke Kuc Mar 07 '19 at 13:54

1 Answers1

1

Try installing the tkdnd binary matching your python installation (64 bit or 32 bit).

RA251995
  • 26
  • 1