Python Tkinter (and TK) offer a set of dialogs that you can use when working with files. By using these you don't have to design standard dialogs your self. Example dialogs include an open file dialog, a save file dialog and many others. Besides file dialogs there are other standard dialogs, but in this article we will focus on file dialogs.
File dialogs help you open, save files or directories. This is the type of dialog you get when you click file,open. This dialog comes out of the module, there's no need to write all the code manually.
Tkinter does not have a native looking file dialog, instead it has the customer tk style. You can see these below.
The file dialog will work on all desktop platforms.
Related course: Python Desktop Apps with Tkinter
file dialogs
tkinter filedialog
The tkinter filedialog comes in several types. Which type you need really depends on your applications needs. All of them are methods calls.
You can open a single file, a directory, save as file and much more. Each dialog made with the example below is a different type of dialog.
1 |
import tkinter.filedialog |
You can create an open file dialog which asks for a filename, and then returns the name of the selected dialog.
1 |
import tkinter as tk |
The appearance of the dialog is different on every operating system. It will look different on
Windows, Mac and Linux (gnome).
Other file dialogs work similar to the example shown above.