I'm doing a small project in Python and I would like to browse a file or directory to get their path.
I'm using Tkinter and I was abble to find only a file browser:
filename = tkFileDialog.askopenfilename(parent=root,title='Open file to encrypt')
or only a directory browser:
dir = tkFileDialog.askdirectory(parent=root, title='Open file to encrypt')
Is it possible to combine these two? THank you for all the answers!
In order to do so, we have to import the filedialog module from Tkinter. The File dialog module will help you open, save files or directories. In order to open a file explorer, we have to use the method, askopenfilename(). This function creates a file dialog object.
File dialogs help you open, save files or directories. This is the type of dialog you get when you click file,open. This dialog comes out of the module, there's no need to write all the code manually. Tkinter does not have a native looking file dialog, instead it has the customer tk style.
No, it's not possible to combine them. The file browser and directory browser have different UIs because they are accomplishing different tasks.
Most programs handle this by differentiating the task in their File menu. You might have a "Select File" or "Select Folder" option. This would lead you to either the File browser or the Directory browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With