我试着使用Tkinter库,但是,我一直收到这个消息,我不知道如何解决它。我在网上看了看,但没有找到这个特定的错误-我这样调用这个库:
from Tkinter import *我得到了这个错误-
TclError = Tkinter.TclError
AttributeError: 'module' object has no attribute 'TclError'我不知道我现在能做什么。谢谢
完整回溯:
Traceback (most recent call last):
File "C:/Users/Shoham/Desktop/MathSolvingProject/Solver.py", line 3, in <module>
from Tkinter import *
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\lib- tk\Tkinter.py", line 41, in <module>
TclError = Tkinter.TclError
AttributeError: 'module' object has no attribute 'TclError'发布于 2015-08-29 02:39:29
您使用from Tkinter import *导入了(大部分)模块中的所有内容。这意味着(主要)该模块中的所有内容现在都包含在全局名称空间中,并且在引用其中的内容时不再需要包括模块名称。因此,将Tkinter的TclError对象简单地称为TclError而不是Tkinter.TclError。
发布于 2015-08-29 02:49:41
就像@ErezProductions说的那样。您要么必须导入所有内容并直接访问它,要么只导入模块。
from Tkinter import *
TclError或
import Tkinter
Tkinter.TclError发布于 2015-08-29 03:11:11
问题似乎出在"C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\lib-tk\Tkinter.py中
lib-tk\Tkinter.py中常规python安装导入与PortablePython2.7.6.1\App\lib\lib-tk\Tkinter.py中的不同
try:
import _tkinter
except ImportError, msg:
raise ImportError, str(msg) + ', please install the python-tk package'
tkinter = _tkinter # b/w compat for export
TclError = _tkinter.TclError然后,在PortablePython中使用Tkinter的位置将改为使用_tkinter。这看起来像是PortablePython中的一个bug。
该文件的完整内容为here。根据注释替换C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\lib-tk\Tkinter.py中的文件可修复此问题。
https://stackoverflow.com/questions/32277700
复制相似问题