人们问起python版本是因为tk.filedialog在2.x中拼写不同。但是,我怀疑您的问题是空闲在托管环境中运行代码,该环境掩盖了您未发布的代码中的错误,该错误未正确导入tkinter.filedialog。为说明起见,以下内容来自标准的3.4.2控制台解释器
>>> import tkinter as tk>>> tk.filedialogTraceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'module' object has no attribute 'filedialog'
这是Idle’s Shell中的相同语句。
>>> import tkinter as tk>>> tk.filedialog<module 'tkinter.filedialog' from 'C:\Programs\Python34\lib\tkinter\filedialog.py'>
没有错误的原因是因为空闲已将filedialog子模块导入为
tkinter.filedialog(在sys.modules中)。如果这也是您的问题,那么为您提供的解决方案是在下面添加导入,并引用不带’tk’前缀的’filedialog’。
>>> from tkinter import filedialog>>> filedialog<module 'tkinter.filedialog' from 'C:\Programs\Python34\lib\tkinter\filedialog.py'>>>> filedialog.askopenfilename<function askopenfilename at 0x0000000000498BF8>
如果这不能解决此问题,请编辑您的问题以添加一个真正的最小代码示例,并确切说明如何同时使用Idle和’CMD’(在Windows上是cmd.exe还是什么?)。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)