Tkinter tkFileDialog 不存在 [英] Tkinter tkFileDialog doesn't exist

查看:36
本文介绍了Tkinter tkFileDialog 不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

import tkFileDialog

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

This line throws an error for me, saying

No module named 'tkFileDialog'

看来我的 Python 没有 tkFileDialog.所以我尝试搜索它,但似乎您没有下载"Tkinter,它只是随 Python 一起提供的.为什么我的 Tkinter 缺少 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 3 中导入 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 tkFileDialog in Python 3?

我运行的是 Windows 7 64 位 Python 版本

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

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

任何帮助将不胜感激!

推荐答案

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

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

import tkinter.filedialog
# or
from tkinter import filedialog

这篇关于Tkinter tkFileDialog 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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