使用withdraw和wm_withdraw隐藏tkinter窗口

时间:2019-02-04 05:59:23

标签: python-3.x tkinter

withdrawwm_withdraw有什么区别?

import time
import tkinter as tk

def hide():
    root.withdraw()
    time.sleep(2)
    root.deiconify()

root = tk.Tk()
tk.Button(root, text = 'hide', command = hide).pack()
root.mainloop()

单击“隐藏”按钮时,窗口被隐藏。它从面板(任务栏)消失,并且在任务视图(所有打开的窗口的同时视图)中2秒钟不可见。

import time
import tkinter as tk

def hide():
    root.wm_withdraw()
    time.sleep(2)
    root.deiconify()

root = tk.Tk()
tk.Button(root, text = 'hide', command = hide).pack()
root.mainloop()

相同的代码,但用wm_withdraw代替withdraw。再次,单击“隐藏”按钮使任务栏条目和窗口本身都不可见2秒钟。

这两个之间有什么区别吗?我应该使用哪一个?此外,我应该使用deiconify还是wm_deiconify?所有四个组合(withdrawdeiconifywm_withdrawdeiconifywithdrawwm_deiconifywm_withdraw,{{1} })似乎做的完全一样。是否有任何应用程序可以执行不同的操作?

2 个答案:

答案 0 :(得分:1)

它们之间没有区别-它们(withdrawdeiconify)只是wm_对应对象的简称。

Wm class下与Window manager进行交互的所有功能也是如此。

答案 1 :(得分:1)

withdraw和wm_withdraw之间没有区别。我无法指定执行此操作的原因,但是这是tkinter的来源,我们在其中包含行withdraw = wm_withdraw(这很清楚两个调用都以相同的方法结束):

def wm_withdraw(self):
    """Withdraw this widget from the screen such that it is unmapped
    and forgotten by the window manager. Re-draw it with wm_deiconify."""
    return self.tk.call('wm', 'withdraw', self._w)
withdraw = wm_withdraw