的OP要求與Tkinter的一個解決方案,它是不可用,但是一個解決方案是可能的wxPython鳳凰
####### Retrieve a list of directories with wxPython-Phoenix - tested on python3.5
### installation instruction for wxPython-Phoenix : https://wiki.wxpython.org/How%20to%20install%20wxPython#Installing_wxPython-Phoenix_using_pip
### modified from : https://wxpython.org/Phoenix/docs/html/wx.lib.agw.multidirdialog.html
import os
import wx
import wx.lib.agw.multidirdialog as MDD
# Our normal wxApp-derived class, as usual
app = wx.App(0)
dlg = MDD.MultiDirDialog(None, title="Custom MultiDirDialog", defaultPath=os.getcwd(), # defaultPath="C:/Users/users/Desktop/",
agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)
if dlg.ShowModal() != wx.ID_OK:
print("You Cancelled The Dialog!")
dlg.Destroy()
paths = dlg.GetPaths()
#Print directories' path and files
for path in enumerate(paths):
print(path[1])
directory= path[1].replace('OS (C:)','C:')
print(directory)
for file in os.listdir(directory):
print(file)
dlg.Destroy()
app.MainLoop()
我不知道了一大堆關於它的,但快速谷歌搜索發現[此鏈接](https://mail.python.org/pipermail/tkinter-discuss/2011-January/002735.html)。你做了很多(任何)研究嗎? – 2015-02-09 20:53:01
@AdamSmith這只是一個循環,繼續到'askdirectory',這不完全是OP想要的。 – nbro 2015-02-09 20:53:59
@Rinzler我在tkinter.ask目錄下的多個目錄的第一個結果是用適當的代碼發佈的新聞組發帖之後低估了這個問題:「沒有更好的方法可以做到這一點,但是這裏有一點竅門。」 downvote是爲「這個問題沒有顯示任何研究努力。」 – 2015-02-09 20:55:53