打印标签的文件路径

Printing a file path to a label

我正在使用 python 编写一个 windows 应用程序,我试图获取 C:\Users\\AppData\Roaming 中特定文件夹的路径 文件夹并将其打印到标签上。我已经尝试过文件对话框,它只允许我 select 一个文件而不是一个文件夹来打印到标签。

def getcache():
    root.filename = filedialog.askopenfilename(initialdir="%appdata%", title="Select Cache Folder")

这是我通常用来获取特定文件的方法。但在这种情况下,我正在寻找一个文件夹来打印到标签上。

如果您正在使用 Tkinter,您可以尝试使用 askdirectory:

from tkinter import filedialog
cache_folder = filedialog.askdirectory(initialdir="%appdata%", title="Select Cache Folder")