Registry / web-framework / tkinterdnd2

tkinterdnd2

JSON →
library0.5.0pypypi✓ verified 86d ago

TkinterDnD2 is a Python wrapper for George Petasis' tkDnD Tk extension version 2, enabling robust drag-and-drop functionality in Tkinter applications. It provides interfaces for registering widgets as drop targets and handling dropped data, including files, text, and custom types. The library is currently at version 0.4.3 and sees sporadic but active maintenance, focusing on cross-platform compatibility and stability for Tkinter projects.

pip install tkinterdnd2
INSTALL
IMPORT
SIG · TKINTERDND2
T
tkinterdnd2
web-frameworkpythonv0.5.0
Install
1.5s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TkinterDnD
from tkinterdnd2 import TkinterDnD
import tkinterdnd2; app = tkinterdnd2.TkinterDnD()
The main class `TkinterDnD` is directly importable from the top-level package. Importing the package directly then referencing `tkinterdnd2.TkinterDnD` works but is less idiomatic.
DND_FILES
from tkinterdnd2 import DND_FILES
Required for specifying that a widget should accept file drops.

This quickstart demonstrates setting up a basic Tkinter window with a label that acts as a drag-and-drop target. It accepts file drops and prints the paths to the console, updating the label with the first dropped item's path.

import tkinter as tk from tkinterdnd2 import DND_FILES, TkinterDnD class MyDNDApp(TkinterDnD.Tk): def __init__(self): super().__init__() self.title("TkinterDnD2 Drop Example") self.geometry("400x300") self.dnd_label = tk.Label( self, text="Drag & drop files here!", width=40, height=10, relief="groove", bg="lightgray" ) self.dnd_label.pack(padx=20, pady=20) # Register the label as a drop target for files self.dnd_label.drop_target_register(DND_FILES) # Bind the drop event to a handler function self.dnd_label.dnd_bind('<<Drop>>', self.handle_drop) def handle_drop(self, event): # event.data contains the dropped data (e.g., file paths) # It's a space-separated string if multiple files are dropped dropped_items = event.data.strip().split(' ') # Basic parsing self.dnd_label.config(text=f"Dropped: {dropped_items[0]}\n({len(dropped_items)} items)") print(f"Dropped items: {dropped_items}") if __name__ == "__main__": app = MyDNDApp() app.mainloop()
Debug
Known issues
gotchaThe underlying `tkDnD` Tk extension is required for `tkinterdnd2` to function. If Tkinter is not correctly configured to find it, you might encounter `_tkinter.TclError` messages.
fix
Ensure your Tkinter distribution includes `tkDnD` or manually place `tkdnd` files in an accessible location (e.g., `TCL_LIBRARY` path). Check `tkinterdnd2` GitHub for OS-specific installation notes and troubleshooting.
affects: All versions
gotchaWhen inheriting `TkinterDnD.Tk` or creating a `TkinterDnD.Tk()` instance, it's crucial to call `self.TkinterDnD()` in the `__init__` if not using the inheritance approach (i.e., `root = tk.Tk(); root = TkinterDnD.TkinterDnD(root)`). For best practice, inherit `TkinterDnD.Tk` directly.
fix
Always inherit your main application window from `tkinterdnd2.TkinterDnD.Tk` (e.g., `class MyApp(TkinterDnD.Tk):`). If you must use a standard `tk.Tk` instance, explicitly create a `TkinterDnD` object and pass the root window: `root = tk.Tk(); dnd_manager = TkinterDnD.TkinterDnD(root)`.
affects: All versions
breakingPrior to version 0.4.3, `tkinterdnd2` had less robust platform detection, potentially leading to issues on non-Windows systems, especially regarding file path parsing or DND initialization.
fix
Upgrade to version 0.4.3 or newer to benefit from improved platform detection and stability fixes. `pip install --upgrade tkinterdnd2`.
affects: <0.4.3
Errors
Common errors & fixes
_tkinter.TclError: couldn't load file "tkdnd2.8.tcl": no such file or directory
The underlying `tkDnD` Tk extension, which `tkinterdnd2` wraps, cannot be found by your Tkinter installation. This often happens if Tkinter is not configured correctly or the extension files are missing.
fix
Consult the `tkinterdnd2` GitHub page or `tkdnd` documentation for instructions on how to ensure the TkDnD extension is properly installed and discoverable by your Tkinter environment. This may involve installing system packages or placing `.tcl` files manually.
ModuleNotFoundError: No module named 'tkinterdnd2'
The `tkinterdnd2` Python package has not been installed in your current Python environment.
fix
Install the package using pip: `pip install tkinterdnd2`.
AttributeError: 'Tk' object has no attribute 'drop_target_register'
You are attempting to use drag-and-drop methods like `drop_target_register` on a standard `tkinter.Tk` object instead of an instance that has been augmented by `tkinterdnd2`.
fix
Ensure your main application window inherits from `tkinterdnd2.TkinterDnD.Tk` (e.g., `class MyApp(TkinterDnD.Tk):`) or explicitly pass your `tk.Tk` instance to `TkinterDnD.TkinterDnD()` to initialize the DND functionality (e.g., `root = tk.Tk(); dnd_manager = TkinterDnD.TkinterDnD(root)`).
Upgrade
Version history
0.5.0latest on PyPI · released Jun 7, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
tkinterdnd2 — pip install tkinterdnd2 · libregistry