最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - tkinter askdirectory not returning correct name - Stack Overflow

programmeradmin0浏览0评论

I'm using tkinter askdirectory to get a user selected folder name in Win 10. For a directory called 'Documents Nig 30Jan2025' the code returns D:/Documents for a directory on a usb attached drive. For other directories on the drive it returns the full directory name, eg 'Zipped folder 1'. If I rename the Documents folder eg to 'Documentx Nig 30Jan2025' the code still returns D:/Documents .

The code is :

from tkinter import filedialog as fd 
from tkinter import Tk  

dirOptions = {"title": "Select Directory","mustexist": True}  

root = Tk(); root.withdraw()
folder = r'{}'.format(fd.askdirectory(**dirOptions))   
print("folder - ",folder) 
root.destroy()

I can't find why this is happening. Would appreciate how to get the full folder name. Thanks.

I tried selecting other folder names on the C and D drive and they all show the correct folder name.your text

发布评论

评论列表(0)

  1. 暂无评论