Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browsing file or directory Dialog in Python

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!

like image 310
user1410771 Avatar asked May 22 '12 16:05

user1410771


People also ask

How do you browse files in Python?

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.

What is file dialog in Python?

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.


1 Answers

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.

like image 68
Brandon Avatar answered Sep 28 '22 20:09

Brandon