tkinter inter-windows drag and drop support
Asked Answered
E

1

1

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!

Eclecticism answered 4/3, 2021 at 9:2 Comment(3)
Are you building the extension package on the Tcl/Tk side with stubs enabled? If you aren't, that's going to be a major headache. With stubs enabled (and built originally against the minimum API version that you wish to support) setting up the whole Tcl side at runtime will be just a matter of putting the right directory on the TCLLIBPATH or auto_path. (Tkdnd seems to have a non-trivial package index file…)Glenoid
actually, I don't build it by myself but just downloading the compiled files from the releases, so I don't know whether or not stubs are enabled. my problem is more related to how to configure the setup.py to build a wheel using the compiled files rather than compiling the tcl files.Eclecticism
Alas, I don't know so much about building Python wheels; my current project only consumes them (as it has some parts that require a cross-compiler targeting embedded ARM processors, which requires a totally different toolchain to normal code). But as long as the Tcl side is kept correct relative to each other — especially relative to the package index file — and built with stubs enabled, it ought to load into whatever is available; it probably doesn't need much special path handling otherwise.Glenoid
E
1

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!

Eclecticism answered 5/4, 2021 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.