简体   繁体   English

Mac版的Enthought-Canopy中与Tkinter发生冲突

[英]conflict with Tkinter in Enthought-Canopy for mac

I am having problems trying to compile a simple tkinter gui using Enthough-Canopy in mac. 我在尝试在Mac中使用Enthough-Canopy编译简单的tkinter gui时遇到问题。 this is the code I am trying to compile: 这是我要编译的代码:

from Tkinter import *
root= Tk();
root.title('Toplevel')
Label(root,text='This is the Toplevel').pack(pady=10)
root.mainloop()

This is the message I receive: 这是我收到的消息:

ImportError                               Traceback (most recent call last)
/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-
x86_64/Canopy.app/Contents/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in 
execfile(fname, *where)
    181             else:
    182                 filename = fname
--> 183             __builtin__.execfile(filename, *where)
/var/folders/m1/70f55r290cz7j_sjc010k0n00000gn/T/tmp1gLNQA.py in <module>()
----> 1 from Tkinter import *
      2 
      3 root= Tk();
      4 
      5 root.title('Toplevel')
/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-
x86_64/Canopy.app/Contents/lib/python2.7/lib-tk/Tkinter.py in <module>()
     37     # Attempt to configure Tcl/Tk without requiring PATH
     38     import FixTk
---> 39 import _tkinter # If this fails your Python may not be configured for Tk
     40 tkinter = _tkinter # b/w compat for export
     41 TclError = _tkinter.TclError
ImportError: dlopen(/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx- 
x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so, 2): Library not loaded: 
/Library/Frameworks/Python.framework/Versions/111.222.33344/lib/libtcl8.5.dylib
 Referenced from: /Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-
x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so
  Reason: image not found

The main problem is TK or TCL, but it is already installed and working good (the code goes fine in Aptana studio 3), but when I try to run it in Canopy it fails. 主要问题是TK或TCL,但是它已经安装并且可以正常工作(Aptana studio 3中的代码运行正常),但是当我尝试在Canopy中运行它时,它失败了。

Thank you for your time and support 感谢您的时间和支持

By default, Canopy uses a Qt4 graphical backend, which would cause problems since these two backends cannot coexist in a single process. 默认情况下,Canopy使用Qt4图形后端,这将导致问题,因为这两个后端无法在单个进程中共存。 To fix this, in the Canopy Preferences > Python tab, you can change the PyLab backend from Interactive (Qt4) to Inline (SVG) to allow the use of Tkinter. 为了解决这个问题,在Canopy Preferences> Python选项卡中,您可以将PyLab后端从Interactive(Qt4)更改为Inline(SVG)以允许使用Tkinter。

You can either switch between these two settings depending on the project (recommended, because the default Qt backend is generally more attractive) or just specify the Inline (SVG) if you don't see the need to go back. 您可以根据项目在这两个设置之间进行切换(建议使用,因为默认的Qt后端通常更具吸引力),或者如果看不到需要返回的内容,则只需指定内联(SVG)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM