簡體   English   中英

當我打開 tkinter 保存文件對話框時,如何隱藏 tkinter window?

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

我的程序使用tkinter.asksaveasfilename function 將文本保存到另一個位置,但是當用戶打開另存為對話框時,tkinter 的空方塊 window 也會彈出。 我的程序在控制台上運行,所以我不需要 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. 如果我在asksaveasfilename root.withdraw之后使用 root.withdraw,則在用戶關閉另存為對話框后,方空 tkinter window 將關閉。

asksaveasfilename保存文件名 function 處於活動狀態時,有沒有辦法隱藏 tkinter window?

這對你有用嗎?:

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()

它適用於我(Windows 10)。 我認為它也應該適用於 Linux 和 MacOS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM