Search code examples
pythonwindows-explorer

In python is there a way to use the windows explorer to create a file path which can then be returned as a string?


I am making a program to manage a database and i need a nice way of choosing the save locations of files within the program. I was wondering if it is possible to open windows explore from my program, select a folder to save a file in, enter the file name and return the file path as a string to the main program.


Solution

  • Look up the Tkinter options in tkFileDialog

    I don't think you necessarily need to put together a fully working GUI, you can simply call the method and select a folder location and then use that selected location in your code.

    A simplistic example would be:

    import Tkinter, tkFileDialog
    
    root = Tkinter.Tk()
    
    x = tkFileDialog.askopenfilename() # Can pass optional arguments for this...
    
    root.destroy()