Python中实现两个窗口的交互出现

  1. 要求点击按钮出现第二个窗口,第一个窗口消失。
  2. 在第二个窗口中点击关闭按钮时,第二个窗口消失,第一个窗口出现。
  • 实现方法
  1. 这里mainloop()函数和destroy()函数有时候无法实现。

  2. 窗口1(rt1),窗口2(rt2),总方法dis()

  3. 可以把整个代码块写在一个方法里面(除import语句外)在函数的最后和第二个界面的关闭监听方法里面写出方法调用。

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

     

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值