默认情况下,Tkinter 是否带有文件对话框?

Does Tkinter come with File Dialogs by default?

我一直在阅读 TKDocs here,查看部分 Windows 和对话框。其中一部分提供了在硬盘驱动器上保存、打开和定位文件的各种方法。

from Tkinter import filedialog
dirname = filedialog.askdirectory()

然而,在尝试了一个之后,我收到了以下错误:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    a()
  File "<pyshell#8>", line 2, in a
    from Tkinter import filedialog
ImportError: cannot import name filedialog

文档中提供的代码是用 Python 完成的 3. 我只修改了 Tkinter 上的 import(大写与小写)。

我的问题是:

Tkinter 中的文件对话框是否在其他地方,或者它们是您需要上网的东西,还是根本没有提供?我有 python 2.7.6.

您需要从 Tkinter 包中导入 tkFileDialog。参考 this

from Tkinter import *
from tkFileDialog import *