【发布时间】:2015-06-01 22:10:07
【问题描述】:
我正在学习 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
任何指向我在这里缺少的东西的指针都会有很大的帮助。
【问题讨论】:
-
你确定你idle中使用的python版本和命令行中使用的是同一个版本吗?
-
@BryanOakley 是的,我正在使用相同的版本。这是相同 IDLE 的 sn-p:Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32 Python CmdLine: Python 2.7 (r27:82525 , Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
标签: python-2.7 tkinter tk