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 tkinterdnd2Verified import paths — ran on the pinned version, not inferred.
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.
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.
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)`.
Upgrade to version 0.4.3 or newer to benefit from improved platform detection and stability fixes. `pip install --upgrade tkinterdnd2`.
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.
Install the package using pip: `pip install tkinterdnd2`.
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)`).
No dependency data recorded yet.