1

In my script I am using tkinterdnd2 library to achieve drag and drop functionality from Windows explorer into my tkinter UI.

from tkinterdnd2 import TkinterDnD, DND_FILES
import tkinter as tk

class TkWindow:
    def __init__(self):
        self.window = TkinterDnD.Tk()
        self.tbox = tk.Listbox(self.window)
        self.tbox.pack(fill=tk.BOTH)
        self.tbox.drop_target_register(DND_FILES)
        self.tbox.dnd_bind('<<Drop>>', self.tk_files_dropped)
        self.window.mainloop()

    def tk_files_dropped(self, event):
        messagebox.showinfo("x", event.data)

TkWindow()

When I launch the script - everything works.

But when I freeze the project to a single EXE with PyInstaller, and run it, I get this error:

Unable to load tkdnd library.

I tried this solutions already:

  1. I added the pyinstaller-hook as instructed in the tkinterdnd2 repository:

    from PyInstaller.utils.hooks import collect_data_files, eval_statement
    datas = collect_data_files('tkinterdnd2')

  2. I add --collect-all tkinterdnd2 when executing build command.

  3. I tried copying tkdnd2.8 to tcl8.6 as mentioned in this answer

  4. I tried getting rid of venv and installing all the packages directly into base python interpreter.

deshu
  • 74
  • 11
  • when I was having issues with pyinstaller, I tried different methods which didn't work until I run pip uninstall typing in command prompt and it worked fine. – CCCC Sep 27 '21 at 14:47
  • @CEO do you mean uninstalling and installing pyinstaller? Tried that too. – deshu Sep 27 '21 at 15:12
  • not really. Let me write it in the answer section then – CCCC Sep 27 '21 at 15:14
  • Does your code run without any error in the code editor? – CCCC Sep 27 '21 at 17:20
  • Yes. Without any error. Full repo is here: https://github.com/deshudiosh/PyWykladzinyLayout – deshu Sep 28 '21 at 18:37

2 Answers2

2

I used --collect-all TkinterDnD2 with upperCase.

cigien
  • 55,661
  • 11
  • 60
  • 99
Peter
  • 21
  • 2
  • I already switched to wxpython but I am glad you answered. Seams that this might be the reason. – deshu Dec 06 '21 at 01:54
0

Use this now when converting a Python file to exe(pyinstaller.exe --collect-all TkinterDnD2 --windowed yor_app.py) And then you will find the files and folders of the program that was created, you will find a file named TCL. Copy the tkdnd folder into it and then run the exe file

VENOM
  • 1
  • 1
  • pyinstaller.exe --collect-all TkinterDnD2 --windowed yor_app.py – VENOM May 18 '22 at 20:18
  • 1
    Doesn't the other answer already cover this? In any case, please mark code with backticks (`\``), not parentheses. See https://stackoverflow.com/help/formatting – Chris May 19 '22 at 01:43