Reputation: 5
I want to drag and drop items onto the gui. I believe thats possible with tkinter? But whenever I try to run this, I get this error:
File "/Users/USER/Documents/GitHub/RegExorcist/regexorcist.py", line 92, in <module>
window = TkinterDnD.Tk()
^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/tkinterdnd2/TkinterDnD.py", line 285, in __init__
self.TkdndVersion = _require(self)
^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/tkinterdnd2/TkinterDnD.py", line 55, in _require
raise RuntimeError('Unable to load tkdnd library.')
RuntimeError: Unable to load tkdnd library.
This is what I added to my code:
from tkinterdnd2 import TkinterDnD, DND_FILES
# GUI
window = TkinterDnD.Tk()
window.title('RegExorcist')
# Bind drag-and-drop events
window.drop_target_register(DND_FILES)
window.dnd_bind('<<Drop>>', on_drop)
window.dnd_bind('<<DragEnter>>', on_drag_enter)
I have installed tkinter, tkinterdnd, tkinterdnd2
How can I make the code work and remove the error?
Extra information:
I'm on VC Code. I have Python 3.12.3 /opt/homebrew/bin/python3, Python 3.12.3 /usr/local/bin/python3 and one Python 3.9.6 /usr/bin/python3. I use the first one for it. When I use the second one, tkinterdnd becomes yellow.
Upvotes: 0
Views: 251
Reputation: 5
I installed tkinterdnd2-universal instead of tkinterdnd2 and that fixed the issue.
Upvotes: 0