python-2.7 - Python Tkinter抛出Tcl错误

标签 python-2.7 tkinter tk

我正在学习 Python 中的基本 GUI,我遇到了一个示例示例,可以从 Stack Overflow 上的文件资源管理器中读取文件名。 .

from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)

当我尝试在 IDLE 中运行它时,这个特定的脚本工作正常,但如果我在 Windows 7 中从命令提示符尝试,它就不会运行。

Python 版本:2.7。这是我得到的输出错误。
>>> from Tkinter import Tk
>>> from tkFileDialog import askopenfilename
>>> Tk().withdraw()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\Lib\lib-tk\Tkinter.py", line 1685, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
C:/Python27/lib/tcl8.5 D:/PyProj/lib/tcl8.5 D:/lib/tcl8.5 D:/PyProj/library D:/library D:/tcl8.5.2/library D:/tcl8.5.2/library

This probably means that Tcl wasn't installed properly

任何指向我在这里缺少的内容的指针都会有很大帮助。

最佳答案

你只需要从tcl文件夹复制两个文件夹到Lib文件夹

tcl8.5 和 tk8.5

关于python-2.7 - Python Tkinter抛出Tcl错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29320039/

相关文章:

python - 如何在 Aegis Blade 中运行 Selenium

python - 提高 Tkinter 文本的 Pygments 语法突出显示速度

python - Tkinter:如何确定 Toplevel 的位置?

python - Tkinter 启动画面和主循环外的多处理

django - 使用 urls.py 时出现 TypeError Django

python - 无法运行 Pybrain 教程

python 脚本 envoke -h 或 --help 如果没有选择任何选项

python - 如何获得覆盖整个 Tkinter Canvas 的绘图?

python - Python中Tk的背景颜色

Tkinter 网格几何管理器大小传播(带粘性)