tkinter filedialog
Python hosting: Host, run, and code Python in the cloud!
tkFileDialog is a module with open and save dialog functions. Instead of implementing those in Tkinter GUI on your own.
This page is a collection of python tkinter file dialogs. The code is displayed here along with screenshots. Dialogs included in tkinter let you ask for a filename or directory.
tkinter file dialogs are easy to use, but not that easy to find out how to use. The main problem is that there is no simple example of how to do it. This article tries to fill the gap.
Related course:
Tkinter Open File
The askopenfilename function to creates an file dialog object. The extensions are shown in the bottom of the form (Files of type).
tkinter.tk.askopenfilename is an extension of the askopenfilename function provided in Tcl/Tk.
The code below will simply show the dialog and return the filename. If a user presses cancel the filename is empty. On a Windows machine change the initialdir to “C:\”.
Python 2.7 version:
from Tkinter import *from Tkinter import * |
Python 3 version:
|
Here is an example (on Linux):

Tkinter Save File
The asksaveasfilename function prompts the user with a save file dialog.
Python 2.7 version
|
Python 3 version
|
Tkinter Open Directory
Consider a scenario where your program needs to get a directory, the user clicked on the ok button and now you want to determine the path.
The askdirectory presents the user with a popup for directory selection.
Python 2.7 version
|

If you are new to programming Tkinter, I highly recommend this course.
Leave a Reply: