导入整个包在 IDLE 中有效,但在 shell 中无效。以下在 IDLE 中工作正常:
import tkinter as tk
tk.filedialog.askopenfilename()
在 shell 中,我收到此错误:
AttributeError: 'module' object has no attribute 'filedialog'
我知道我必须import tkinter.filedialog
在 shell 中完成这项工作。
为什么IDLE和shell有区别?我怎样才能让 IDLE 像 shell 一样?让脚本在 IDLE 中运行而在 shell 中失败可能会令人沮丧。
我正在使用 Python 3.4。