- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Save File Dialog Box in Tkinter
We often use Open and Save Dialog. They are common across many applications and we already know how these dialogs work and behave. For instance, if we click on open, it will open a dialog to traverse the location of the file. Similarly, we have the Save Dialog.
We can create these dialogs using Python tkFileDialog package. In order to work with the package, we have to import this in our environment.
Type the following command to import the tkFileDialog package in the notebook,
from tkinter.filedialog import asksaveasfile
In this example, we will create an application that will save the file using the dialog.
#Import necessary Library from tkinter import * from tkinter.filedialog import asksaveasfile #Create an instance of tkinter window win= Tk() #Set the geometry of tkinter window win.geometry("750x250") #Define the function def save_file(): f = asksaveasfile(initialfile = 'Untitled.txt', defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")]) #Create a button btn= Button(win, text= "Save", command= lambda:save_file()) btn.pack(pady=10) win.mainloop()
In the given code, we have created a "save" button to open the save dialog box using the filedialog module in tkinter.
Click the "Save" button to save the File using the Dialog Box.
- Creating a prompt dialog box using Tkinter?
- How to give Tkinter file dialog focus?
- Raise a "File Download" Dialog Box using Perl
- How To Raise a "File Download" Dialog Box in Python?
- What is the correct way to implement a custom popup Tkinter dialog box?
- How to raise a "File Download" Dialog Box in Python CGI Programming?
- How to bring a dialog box to appear at the front in a Tkinter module of Python?
- How do we define a dialog box in HTML?
- How to add check box list in alert dialog?
- How to create a Confirmation Dialog Box in Java?
- How to work with Alerts Dialog box in ReactNative?
- How to create a modal dialog in tkinter?
- How to create a Custom Dialog box on Android?
- How to dismiss the dialog with the click on outside of the dialog box in android?