擅长:python、mysql、java
<p>你们可以把窗户藏起来</p>
<pre><code>root.withdraw()
# or
root.iconify()
</code></pre>
<p>再来一次</p>
<pre><code>root.deiconify()
</code></pre>
<hr/>
<p>禁用按钮</p>
<pre><code>b['state'] = 'disabled'
</code></pre>
<p>启用按钮</p>
<pre><code>b['state'] = 'normal'
</code></pre>
<hr/>
<p><strong>编辑:</strong>如@acw1668在评论中所述,当用户使用标题栏上的关闭按钮[X]时,需要<code>win.protocol()</code>运行<code>close_second</code></p>
<pre><code>import tkinter as tk # PEP8: `import *` is not preferred
# - functions -
def close_second():
win.destroy()
b['state'] = 'normal'
root.deiconify()
def open_second():
global win
b['state'] = 'disabled'
#root.iconify()
root.withdraw()
win = tk.Toplevel()
win_b = tk.Button(win, text="Close Second", command=close_second)
win_b.pack()
# run `close_second` when user used closing button [X] on title bar
win.protocol("WM_DELETE_WINDOW", close_second)
# - main -
root = tk.Tk()
b = tk.Button(root, text="Open Second", command=open_second)
b.pack()
root.mainloop()
</code></pre>