Is there any way that you can ask the user to choose files or folders without using multiple statements? I know there is filedialog
and I can use askopenfilenames()
and Directory()
to make the user choose in multiple statements but is there something that combines the two together and being able to select multiple at the same time?? If there isn't how can I make the user be able to select multiple files or directories at the same time? thanks in advance!
Asked
Active
Viewed 99 times
0
-
1I don't understand your question. At a point I feel like you are asking how to make a user choose a directory AND a file and at another point I feel like your asking how to make the user choose multiple files/directories – Delrius Euphoria Jul 30 '22 at 23:52
-
it's asking the user to choose directories and files in the same window but being able to choose multiple ones at the same time. so for example I click on a button and a filedialog opens and i go to documents and then I would like to be able to click different files and directories and click on open and put all of these into a list – Jul 31 '22 at 00:45
1 Answers
0
What you are trying to accomplish is not possible as there is a reason why you don't have the option of either selecting folders or directories.
An alternate solution could be to have a user select a directory (e.g Documents) and create a list with all the files and directories inside that user selected directory as shown below.
from tkinter import filedialog
import tkinter as tk
import os as os
directory = os.path.join(tk.filedialog.askdirectory())
dir_content = os.listdir(directory)
# this creates a list with all files and directories inside a supplied directory

Jai Amin
- 16
- 4
-
I see, that's something that should be added I feel like. i created something like this but then with `os.walk`to get the path to each file that is located in that directory and if someone wants to click files the same thing but then with `askopenfilename`. what you said works perfectly fine too. – Jul 31 '22 at 11:07