简体   繁体   English

将文件路径打印到 label

[英]Printing a file path to a label

I am writing a windows application using python where I am trying to get the path to a specific folder in the C:\Users\\AppData\Roaming folder and print it to a label. I am writing a windows application using python where I am trying to get the path to a specific folder in the C:\Users\\AppData\Roaming folder and print it to a label. I have tried the filedialog and it only lets me select a file rather than a folder to print to the label.我已经尝试了文件对话框,它只让我 select 一个文件而不是一个文件夹打印到 label。

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

This is what I normally use to get a specific file.这是我通常用来获取特定文件的方法。 But I am looking for a folder in this case to print to a label.但在这种情况下,我正在寻找一个文件夹以打印到 label。

If you are using Tkinter you can try with askdirectory:如果您使用的是Tkinter ,您可以尝试使用 askdirectory:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM