简体   繁体   中英

What to prevent multiple toplevels from appearing in Tkinter?

What can I do to prevent toplevels from appearing in Tkinter?

from tkinter import *
import os

root = Tk()

def top_level():
    a=Toplevel()
    l=Label(a,text="yeni")
    l.pack()

    def yeni():
        root.destroy()
        os.startfile("a.pyw")
    
        top_level()
    
    bt1= Button(a,  text="Top Level",command= yeni)
    bt1.pack()
    a.mainloop()

bt= Button(root,  text="Top Level",command= top_level)
bt.pack()

root.mainloop()

It outputs like this:

截屏

a is the Toplevel so a.destroy()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM