1

How can I select multiple files from multiple directories? in Tkinter

I want to note the address of the files which are in different directories I have tried using askopenfilenames() file dialog and askopenfilename(...,multiple=True) but they haven't allowed me to select multiple files from different directories.

Is there any other file dialog that can do. Sorry if this a repeated Question.

1 Answer 1

3

This code might help you

import tkinter,tkinter.filedialog
from tkinter import messagebox

root = tkinter.Tk()
def main():
        files = tkinter.filedialog.askopenfilenames(parent=root,title='Choose files')
        msgbox = tkinter.messagebox.askquestion ('Add files','add extra files',icon = 'warning')
        return list(files), msgbox

files, msgbox = main()

all_files = files

while msgbox =='yes':
    files_2, msgbox = main()
    for i in files_2:
        files.append(i)
    
root.destroy()

all_files contains all the directories selected

Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking about opening multiple askopenfilenames but I was wondering if there is a way with only one. But thanks! guess I will go with this method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.