在有多个窗口的情况下,例如登录的时候,登录成功后如何隐藏登录窗口呢。
使用 withdraw() 实现窗口隐藏 使用 deiconify() 显示窗口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
from tkinter import *
app = Tk()
app.geometry('400x400')
app.title("窗口1")
def open_new_win():
app.withdraw()
subwin = Toplevel()
subwin.geometry('200x200')
subwin.title('窗口2')
btn1 = Button(subwin, text="关闭窗口2 并打开窗口1", command=lambda: open_old_win(subwin))
btn1.pack()
btn1.mainloop()
def open_old_win(subwin):
app.deiconify()
subwin.withdraw()
btn = Button(app, text="打开窗口2 并隐藏当前窗口1", command=open_new_win)
btn.pack()
app.mainloop()
|