简体   繁体   中英

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,

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM