标准对话框filedialog
程序为:from tkinter import *
root = Tk()
def callback():
fileName = filedialog.askopenfilename()
print(fileName)
Button(root, text="打开文件", command=callback).pack()
mainloop()
运行后点击“打开文件”出现如下错误
fileName = filedialog.askopenfilename()
NameError: name 'filedialog' is not defined
如附图所示
请大家帮忙看下是什么问题?谢谢
我们现在的版本,* 不会将这些组件导入了,要我们指定导入才行
from tkinter import *
from tkinter import filedialog
root = Tk()
def callback():
fileName = filedialog.askopenfilename()
print(fileName)
Button(root, text="打开文件", command=callback).pack()
mainloop()
页:
[1]