Python Tkinter抛出Tcl错误 [英] Python Tkinter throwing Tcl error

查看:118
本文介绍了Python Tkinter抛出Tcl错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Python 中学习基本的 GUI,我遇到了一个示例示例,用于从 堆栈溢出.

from Tkinter import Tk从 tkFileDialog 导入 askopenfilenameTk().withdraw() # 我们不想要完整的 GUI,所以不要出现根窗口filename = askopenfilename() # 显示打开"对话框并返回所选文件的路径打印(文件名)

当我尝试在 IDLE 中运行它时,这个特定的脚本运行良好,但如果我在 Windows 7 中从命令提示符尝试运行它,则它不会运行.

Python 版本:2.7.这是我得到的输出错误.

<预><代码>>>>从 Tkinter 导入 Tk>>>从 tkFileDialog 导入 askopenfilename>>>Tk().withdraw()回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>文件C:\Python27\Lib\lib-tk\Tkinter.py",第 1685 行,在 __init__ 中self.tk = _tkinter.create(screenName、baseName、className、interactive、wantobjects、useTk、sync、use)_tkinter.TclError:在以下目录中找不到可用的 init.tcl: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/图书馆这可能意味着 Tcl 没有正确安装

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

解决方案

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

tcl8.5 和 tk8.5

I am learning basic GUI in Python, and I came across a sample example to read file name from file explorer on 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)

This particular script is working fine when I am trying to run it in IDLE, but the same is not running if I am trying from command prompt in windows 7.

Python Version: 2.7. Here is the output error which I get.

>>> 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

Any pointer to what I am missing here can be of great help.

解决方案

You just need to copy two folders from tcl folder to the Lib folder

tcl8.5 and tk8.5

这篇关于Python Tkinter抛出Tcl错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆