Python 3 中的 tkFileDialog 模块在哪里?问题使用简单的对话框在 Python 中选择文件 https://stackoverflow.com/questions/3579568/choosing-a-file-in-python-simple-gui使用以下方式引用模块:
from Tkinter import Tk
from tkFileDialog import askopenfilename
但在 Python 3 中使用它(将 Tkinter 更改为 tkinter 后)会得到:
Traceback (most recent call last):
File "C:\Documents and Settings\me\My Documents\file.pyw", line 5, in <module>
import tkFileDialog
ImportError: No module named tkFileDialog
python 2.7.2 文档 (docs.python.org) 说:
tkFileDialog
Common dialogs to allow the user to specify a file to open or save.
These have been renamed as well in Python 3.0; they were all made submodules of the new tkinter package.
但它没有给出新名称的提示,并且在 3.2.2 文档中搜索 tkFileDialog 和 Askopenfilename 根本不会返回任何内容(甚至没有从旧名称到新子模块名称的映射。)
尝试显而易见的事情是行不通的:
from tkinter import askopenfilename, asksaveasfilename
ImportError: cannot import name askopenfilename
如何在Python 3 中调用askopenfilename() 的等效项?