我目前正在使用 Python 3.8 和 Tcl/Tk 8.6 开发 MacOs Catalina 10.15.6。正如此处所建议的,我从https://sourceforge.net/projects/tkdnd/下载了 Tk 扩展tkdnd2.8 ,并从https://sourceforge.net/projects/tkinterdnd/下载了 Python 包装器TkinterDnD2,然后复制将 tkdnd2.8目录复制到/Library/Tcl,将TkinterDnD2目录复制到/Library/Frameworks/Python.framework/Versions/.../lib/python/site-packages。之后,当尝试执行以下简单代码时:from TkinterDnD2 import *import tkinter as tkroot = TkinterDnD.Tk()它给了我错误:Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/TkinterDnD2/TkinterDnD.py", line 39, in _require TkdndVersion = tkroot.tk.call('package', 'require', 'tkdnd')_tkinter.TclError: can't find package tkdndDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "/Users/Administrador/Desktop/tkdnd_test.py", line 3, in <module> root = TkinterDnD.Tk() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/TkinterDnD2/TkinterDnD.py", line 271, in __init__ self.TkdndVersion = _require(self) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/TkinterDnD2/TkinterDnD.py", line 41, in _require raise RuntimeError('Unable to load tkdnd library.')RuntimeError: Unable to load tkdnd library.由于 tkdnd 不会自动找到/加载(将 tkdnd2.8 文件夹重命名为 tkdnd 也不起作用),我尝试按照 @Ellis Shen 和 @aong152 的建议手动指定库路径。我将tkdnd2.8文件夹复制到tkdnd_test.py文件旁边。不幸的是,当运行以下代码时:from TkinterDnD2 import *import tkinter as tkimport sys, osprint(os.environ.get('TKDND_LIBRARY'))application_path = os.path.dirname(os.path.abspath(__file__))TK_DND_PATH = os.path.join(application_path,'tkdnd2.8')os.environ['TKDND_LIBRARY'] = TK_DND_PATHprint(os.environ.get('TKDND_LIBRARY'))root = TkinterDnD.Tk()我觉得我在这里遗漏了一些东西,但我花了很多时间搜索类似的经历,但未能找到解决方案。任何帮助都感激不尽。
2 回答
慕沐林林
TA贡献2016条经验 获得超9个赞
解决了!您应该放置tkdnd库的文件夹是/Library/Frameworks/Python.framework/Versions/.../lib/。将库放在 /Library/Tcl 上对 Catalina 不起作用。我建议您安装最新 tkdnd 版本(当前为 2.9.3) 。
添加回答
举报
0/150
提交
取消