Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python - Tkinter askquestion Dialog
Next article icon
Python provides a variety of modules with the help of which one may develop GUI (Graphical User Interface) applications.Tkinter is one of the easiest and fastest way to develop GUI applications.While working with files one may need to open files, do operations on files and after that to save file.asksaveasfile() is the function which is used to save user's file (extension can be set explicitly or you can set default extensions also). This function comes under theclass filedialog.Below is the Code:Python3 1==
# importing all files  from tkinterfromtkinterimport*fromtkinterimportttk# import only asksaveasfile from filedialog# which is used to save file in any extensionfromtkinter.filedialogimportasksaveasfileroot=Tk()root.geometry('200x150')# function to call when user press# the save button, a filedialog will# open and ask to save filedefsave():files=[('All Files','*.*'),('Python Files','*.py'),('Text Document','*.txt')]file=asksaveasfile(filetypes=files,defaultextension=files)btn=ttk.Button(root,text='Save',command=lambda:save())btn.pack(side=TOP,pady=20)mainloop()
Output #1: Directory before saving any file (folder is initially empty)asksaveasfile() function in TkinterOutput #2: Dialogbox when user presses the save button (dialog box to save file is opened). You may see in the output Python file as default is selected.Dialogbox when user presses the save buttonOutput #3: Directory after saving 2 Python files (one may also change the type of file)Directory after saving 2 Python files

Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp