我目前正在使用 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
提交
取消