Skip to content
Advertisement

tkinter inter-windows drag and drop support

I’m trying to help the owner of tkdnd generate a wheel and distribute it to Pypi so users could simply install the tkdnd extension with a simple pip install TkinterDnD2.

I’m after this ‘challange’ for the last two days but could not solve it by myself so far, but I’m sure someone with a deep understanding python packaging and installing process could help as solve it in short time.

currently in order to get this extension work you need to do the following steps(as mentioned here):

  1. download the compiled tkdnd files for your os. now go to your base interpreter directory/tcl and copy this folder under. for example:
--<python3.9-directory>
  --tcl
    --tkdnd2.9.2
    ...
  ...

notice – it did not work for me if I created a matching tcl/tkdnd2.9.2 directory in the venv of the project the imported TkinterDnD2

  1. now download the python wrapper and add it you your venv site-packages directory(or base interpreter it’s doesn’t matter). so the python project which will import TkinterDnD2 will look like this:
--<python-test-project>
  --venv
    --Lib
      --site-packages
        --TkinterDnD2
        ...
  ...

now one could successfully run tkdnd extensions.

you can probably tell this is not much like installing the average python library. the problematic thing here is that the extra tkdnd2.9.2 folder is required to be in the tcl folder of your base interpreter.

maybe it is possible to use the package_data and data_files in the setup.py to tell python to add this tcl files during the installation from the wheel, but I’m not sure. see Packaging and distributing projects for full reference.

the incomplete setup.py:

import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
    long_description = fh.read()

setuptools.setup(
    name="TkinterDnD2",
    version="2.9.2",
    author="petasis",
    description="TkDND is an extension that adds native drag & drop capabilities to the Tk toolkit.",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/petasis/tkdnd",
    project_urls={
        "Bug Tracker": "https://github.com/petasis/tkdnd/issues",
    },
    classifiers=[
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 3",
        "Operating System :: OS Independent",
    ],
    packages=setuptools.find_packages(),
    python_requires=">=2, >=3",
    # some extra logic probably belong here
    # ...     
)

you can track the issue here which includes some extra discussions.

very helpful stackoverflow questions:

  1. How to avoid building C library with my python package?
  2. How to Install and Use TkDnD with Python Tkinter on OSX?

very helpful guides:

  1. Packaging and distributing projects
  2. Packaging Python Projects
  3. Python Bindings: Calling C or C++ From Python

any help would be very appreciated!

Advertisement

Answer

Just answering for the case someone else got stuck on it for weeks like I did.

You can see dist repo that pmgagne created here: https://github.com/pmgagne/tkinterdnd2

The package is not yet published on pypi but you can build a wheel and install it following the instructions on this issue I opened: https://github.com/pmgagne/tkinterdnd2/issues/5

Hopefully, the author will build and publish it soon, so you could simply do python -m pip install tkinterdnd2 and enjoy tkinter inter-windows drag and drop support!

If you don’t want to build it your self here’s a wheel download: tkinterdnd2-0.3.0-py2.py3-none-any.zip extract zip and then you can do python -m pip install tkinterdnd2-0.3.0-py2.py3-none-any.whl and then you will be able to import tkinterdnd2 in your python project.

UPDATE

the author did not respond so I forked it published it myself. you can now install simply using

pip install tkinterdnd2

enjoy!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement