Ask multiple directories dialog in Tkinter Ask multiple directories dialog in Tkinter tkinter tkinter

Ask multiple directories dialog in Tkinter


Having had the same problem I developed my own solution. With this you can select one directory at a time then select cancel when you are finished.

The function the returns a list of the directories you have selected.

def fun_directory_selector(request_string: str, selected_directory_list: list, search_directory):    directory_path_string = filedialog.askdirectory(initialdir=search_directory, title=request_string)       if len(directory_path_string) > 0:        selected_directory_list.append(directory_path_string)        fun_directory_selector('Select the next Directory or Cancel to end',                                selected_directory_list,                               os.path.dirname(directory_path_string))    return selected_directory_list


The OP asked for a solution with Tkinter which isn't available but a solution is possible with wxPython-Phoenix

####### 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.htmlimport osimport wximport wx.lib.agw.multidirdialog as MDD# Our normal wxApp-derived class, as usualapp = 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()