tkinter filedialog - 如何获取所选文件的目录?

tkinter filedialog - how to get directory of selected file?

如何获取存储从 tkinter 中选择的文件的文件夹 filedialog

我想做这样的东西:

from tkinter import filedialog as fd
filename = fd.askopenfilename()
print(filename.directory)

你可以使用 os.path.dirname

from tkinter import filedialog as fd
import os

filename = fd.askopenfilename()
print(os.path.dirname(filename))