- 要求点击按钮出现第二个窗口,第一个窗口消失。
- 在第二个窗口中点击关闭按钮时,第二个窗口消失,第一个窗口出现。
- 实现方法
-
这里靠mainloop()函数和destroy()函数有时候无法实现。
-
窗口1(rt1),窗口2(rt2),总方法dis()
-
可以把整个代码块写在一个方法里面(除import语句外)在函数的最后和第二个界面的关闭监听方法里面写出方法调用。
-
import tkinter import tkinter as Tk from tkinter import * def dis(): rt1 = Tk(className='测试') rt1.geometry('600x400+400+200') rt1.title('出车界面') def click1(): rt1.destroy() park() button1 = tkinter.Button(rt1, text='出现第二个界面', bg='blue', width=20, command=click1) button1.pack() rt1.mainloop() def park(): rt2 = tkinter.Tk(className='测试') rt2.geometry('380x200+650+150') t1 = Entry(rt2, show=None) t1.place(x=120, y=10) t2 = Label(rt2, text='车号:') t2.place(x=60, y=10) t3 = Entry(rt2, show=None) t3.place(x=120, y=60) t4 = Label(rt2, text='车主:') t4.place(x=60, y=60) t5 = Label(rt2, text='颜色:') t5.place(x=60, y=100) t6 = Entry(rt2, show=None) t6.place(x=120, y=100) def quxiao(): rt2.destroy() dis() bt1 = Button(rt2, text='确认', width=10, height=1) bt1.place(x=80, y=140) bt2 = Button(rt2, text='返回上一个界面', width=15, height=1, command=quxiao) bt2.place(x=160, y=140) rt2.mainloop() dis()