'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:

screenshot



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source