from tkinter import Tk from tkinter.filedialog import askopenfilename Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing filelocation = askopenfilename() # open the dialog GUI
Here is what the above code is Doing:
1. We import the Tkinter module and its function askopenfilename.
2. We create a Tkinter variable.
3. We then use the askopenfilename function on that variable.
4. We then add a filetype filter so that we only see the files we want to open.
5. We then assign the file location to a variable.