Python Tkinter tkFileDialog 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28590669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:29:59  来源:igfitidea点击:

Tkinter tkFileDialog doesn't exist

pythonpython-3.xtkinter

提问by gfrung4

I'm trying to show a open file dialog using Tkinter in Python. Every example I find seems very easy to use, but they all start with the line:

我正在尝试在 Python 中使用 Tkinter 显示一个打开的文件对话框。我发现的每个示例似乎都很容易使用,但它们都以以下行开头:

import tkFileDialog

This line throws an error for me, saying

这行给我抛出了一个错误,说

No module named 'tkFileDialog'

It seems my Python doesn't have tkFileDialog. So I tried searching for it, but it seems that you don't "download" Tkinter, it just comes with Python. Why is my Tkinter missing tkFileDialog? Is there somewhere I can acquire it so that I can use it?

看来我的 Python 没有tkFileDialog. 所以我尝试搜索它,但似乎您没有“下载”Tkinter,它只是随 Python 一起提供的。 为什么我的 Tkinter 缺少 tkFileDialog?有什么地方可以买到它以便我可以使用它吗?

Another thing I thought is that maybe it has changed names since the examples I've read were written. Is there a different way to import tkFileDialogin Python 3?

我认为的另一件事是,自从我读过的例子写出来后,它可能已经改变了名称。tkFileDialog在 Python 3 中是否有不同的导入方式?

I'm running Windows 7 64-bit, Python version

我正在运行 Windows 7 64 位,Python 版本

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]

Any help would be greatly appreciated!

任何帮助将不胜感激!

采纳答案by gfrung4

That code would have worked fine in Python 2.x, but it is no longer valid. In Python 3.x, tkFileDialogwas renamed to filedialogand placed inside the Tkinter package. Nowadays, you import it like so:

该代码在 Python 2.x 中可以正常工作,但它不再有效。在 Python 3.x 中,tkFileDialog被重命名filedialog并放置在 Tkinter 包中。如今,您可以像这样导入它:

import tkinter.filedialog
# or
from tkinter import filedialog