
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
asksaveasfile() function in Python Tkinter
TKinter is a Python module which is used for GUI programming in Python. We create a Canvas and place our UI components with many properties and behaviors in it. In this article, we will see e how to use the ask essay file function to save files created through Python programs into the local drives.
We first create a canvas on which we again place a button using the TTK dot button function. Then declare another function that will use the ask fine to define the file type and save the file into location in the local drive.
Example
from tkinter import * from tkinter import ttk from tkinter.filedialog import asksaveasfile base = Tk() base.geometry('300x250') def SaveFile(): data = [('All tyes(*.*)', '*.*')] file = asksaveasfile(filetypes = data, defaultextension = data) save_btn = ttk.Button(base, text = 'Click to save file ', command = lambda : SaveFile()) save_btn.pack(side = TOP, pady = 20,padx = 50) mainloop()
Output
Running the above code gives us the following result −
Next on clicking the “click to save file as” button, we get the next window as below.
- Related Articles
- askopenfile() function in Python Tkinter
- Binding function in Python Tkinter
- How to return a JSON object from a Python function in Tkinter?
- Function to close the window in Tkinter
- Tkinter Programming in Python
- How to stop Tkinter after function?
- Collapsible Pane in Tkinter Python
- Progressbar widget in Python Tkinter
- after method in Python Tkinter
- destroy() method in Tkinter - Python
- Different messages in Tkinter - Python
- Python - geometry method in Tkinter
- Mouse Position in Python Tkinter
- Create multiple buttons with "different" command function in Tkinter
- Color game using Tkinter in Python

Advertisements