问题描述
我花了一些时间来寻找在 OSX 平台上使用 Python Tkinter 执行拖放行为的可行解决方案,找到的最可能的解决方案是 TkDnD 库.http://sourceforge.net/projects/tkdnd/files/
I've spent some time to search for workable solution to do Drag and Drop behavior with Python Tkinter on OSX platform, and the most possible solution found is TkDnD library.http://sourceforge.net/projects/tkdnd/files/
但是我找不到任何关于安装的手册或指南,在 OSX 上基本上没有示例.谁能和我分享他们的经验?
However I cannot find any manual or guide about the installation and basically no sample on OSX. Can anyone share their experience with me?
此外,使用 Tkinter 作为 GUI 解决方案不是一个好的选择吗?我的用户都是OSX平台,所有这些机器上都预装了Python.有什么好的建议可以在没有额外安装的情况下找到本机 GUI 支持吗?PyQT 似乎是另一种选择,但不确定它是否需要在客户端机器上额外安装.
Furthermore, is it not a good choice to use Tkinter as a GUI solution? My users are all OSX platform and Python is preinstalled on all these machines. Any good suggestion to find a native GUI support without additional installation? PyQT seems to be another choice, but not sure if it requires the additional installation on Client machine.
推荐答案
我花了几天时间想出如何安装 TkDnD lib,虽然这听起来很简单,但确实让我困惑了一段时间.
I spent a few days to figured out how to install TkDnD lib, although it sounds like an easy question but did confused me a little while.
在 OSX 上安装 TkDnD 的两种方法:A.复制到/System/Library/Tcl/8.x
:OSX 已经预装了 Python,这是安装 Tcl 库的路径.使用 Tk/Tcl 库时会自动加载 TkDnd 库.
Two ways to install TkDnD on OSX:A. Copy to /System/Library/Tcl/8.x
:OSX preinstalled Python already, and this is the path where Tcl library is installed. TkDnd lib will be loaded automatically while using Tk/Tcl lib.
B.将 os.environ['TKDND_LIBRARY']
设置为 TkDnd2.x.dylib 的位置:示例代码:
B. Set os.environ['TKDND_LIBRARY']
to the location of TkDnd2.x.dylib:Sample code:
if sys.platform == 'win32':
if getattr(sys, 'frozen', False):
os.environ['TKDND_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tkdnd2.7')
这篇关于如何在 OSX 上通过 Python Tkinter 安装和使用 TkDnD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!