tkinter 窗口间拖放支持 [英] tkinter inter-windows drag and drop support

查看:56
本文介绍了tkinter 窗口间拖放支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试帮助 tkdnd 的所有者生成一个轮子并将其分发给 Pypi,以便用户可以使用简单的 pip install TkinterDnD2 简单地安装 tkdnd 扩展.

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.

过去两天我一直在关注这个挑战",但到目前为止我无法自己解决,但我相信对 Python 打包和安装过程有深入了解的人可以帮助在短时间内解决它.

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. 下载编译好的tkdnd文件为您的操作系统.现在转到您的基本解释器目录/tcl并将此文件夹复制到下面.例如:
  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
    ...
  ...

注意 - 如果我在导入的 TkinterDnD2 项目的 venv 中创建匹配的 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. 现在下载python包装器并将其添加到您的venv站点包目录(或基础口译员没关系).所以将导入 TkinterDnD2 的 python 项目将如下所示:
  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
        ...
  ...

现在可以成功运行 tkdnd 扩展了.

您可能会说这与安装普通的 Python 库没什么两样.这里的问题是额外的 tkdnd2.9.2 文件夹需要位于基础解释器的 tcl 文件夹中.

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.

也许可以使用 setup.py 中的 package_datadata_files 来告诉 python 在安装过程中从轮子上添加这个 tcl 文件,但是我'我不确定.请参阅打包和分发项目供完整参考.

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.

不完整的 setup.py:

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.

非常有用的 stackoverflow 问题:

very helpful stackoverflow questions:

  1. 如何避免用我的python构建C库包?
  2. 如何安装和使用 TkDnDOSX 上的 Python Tkinter?

非常有用的指南:

  1. 打包和分发项目
  2. 打包 Python 项目
  3. Python 绑定:从 Python 调用 C 或 C++

任何帮助将不胜感激!

推荐答案

只是为其他人像我一样被困了几个星期的情况回答.

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

你可以在这里看到 pmgagne 创建的 dist 仓库:https://github.com/pmgagne/tkinterdnd2

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

该软件包尚未在 pypi 上发布,但您可以按照我打开的有关此问题的说明构建一个轮子并安装它:https://github.com/pmgagne/tkinterdnd2/issues/5

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

希望作者尽快构建并发布它,因此您可以简单地执行 python -m pip install tkinterdnd2 并享受 tkinter 跨窗口拖放支持!

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!

如果你不想自己构建它,这里有一个轮子下载:tkinterdnd2-0.3.0-py2.py3-none-any.zip解压 zip 然后你可以做 python -m pip install tkinterdnd2-0.3.0-py2.py3-none-any.whl 然后你就可以 import tkinterdnd2在你的 python 项目中.

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.

作者没有回应所以我分叉它自己发布了.您现在可以简单地使用

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

pip install tkinterdnd2

享受吧!

这篇关于tkinter 窗口间拖放支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆