Search code examples
pythontkinterdrag-and-drop

Python Tkinter DnD2 root = TkinterDnD.Tk() Unable to load tkdnd library


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 ?


Solution

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