nobo
nobo

Reputation: 125

How do I allow a user to select a file?

Right now, I have this line in my code to hard-code the directory path

dir_path = '/home/user/pywork'

but I would rather let the user select it herself using a construct similar to R's scan(choose.files()).

How do I go about it?

Thanks,

Upvotes: 3

Views: 12741

Answers (1)

Paul Hiemstra
Paul Hiemstra

Reputation: 60944

One option I found after a quick google (python open directory dialog box) is to use TKinter:

import Tkinter, tkFileDialog
root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=root, initialdir="/",
                                    title='Please select a directory')

I found the information here.

Upvotes: 8

Related Questions