使用 Python Tkinter 我试图获取所选文件夹的目录路径。我不想加载文件或导航到文件,但获取文件夹路径,例如
我怎样才能做到这一点?
from Tkinter import *
from tkFileDialog import askopenfilename
def callback():
name= askopenfilename()
print name
errmsg = 'Error!'
Button(text='File Open', command=callback).pack(fill=X)
mainloop()
更新
from Tkinter import *
from tkFileDialog import askopenfilename
from tkinter import filedialog #for Python 3
def callback():
name= askopenfilename()
directory = filedialog.askdirectory()
print directory
errmsg = 'Error!'
Button(text='File Open', command=callback).pack(fill=X)
mainloop()
慕仙森
PIPIONE
相关分类