Browse for file path in python
I remade Roberto's code, but rewritten in Python3 (just minor changes).
You can copy-and-paste as is for an easy demonstration .py file, or just copy the function "search_for_file_path" (and associated imports) and place into your program as a function.
import tkinter
from tkinter import filedialog
import os
root = tkinter.Tk()
root.withdraw() #use to hide tkinter window
def search_for_file_path ():
currdir = os.getcwd()
tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory')
if len(tempdir) > 0:
print ("You chose: %s" % tempdir)
return tempdir
file_path_variable = search_for_file_path()
print ("\nfile_path_variable = ", file_path_variable)
I think TkFileDialog might be useful for you.
import Tkinter
import tkFileDialog
import os
root = Tkinter.Tk()
root.withdraw() #use to hide tkinter window
currdir = os.getcwd()
tempdir = tkFileDialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory')
if len(tempdir) > 0:
print "You chose %s" % tempdir
EDIT: this link has some more examples