
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements