How to Install and Use TkDnD with Python Tkinter on OSX?

后端 未结 4 1196
情话喂你
情话喂你 2020-12-03 16:35

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

4条回答
  •  甜味超标
    2020-12-03 16:52

    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.

    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. 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')
    

提交回复
热议问题