简体   繁体   中英

How can I hide tkinter window when I opened tkinter save file dialog?

My program uses tkinter.asksaveasfilename function to save a text into another location but when user opens save as dialog, tkinter's empty square window also pops-up. My program works on console so I don't need the tkinter window.

I searched the web and stackoverflow but only found root.withdraw funtion to hide tkinter window but when I use it before asksaveasfilename function, save as dialog never pops up. If I use root.withdraw after asksaveasfilename function, square empty tkinter window closes after user closes the save as dialog.

Is there a way to hide tkinter window when asksaveasfilename function is active?

Does this work for you?:

from tkinter.filedialog import asksaveasfilename
import tkinter as tk

# Create the window
root = tk.Tk()
# Hide the window
root.withdraw()

# Now you are free to popup any dialog that you need
print(asksaveasfilename())

# Destroy the window
root.destroy()

It works for me (Windows 10). I think that it should work for Linux and MacOS too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM