tkinter.Tk.destroy


Definition
The method destroy the Tk Widget.

Syntax
Tk.destroy

Examples
The ButtonPress triggers the event which created new Tk widget while destroyed main Widget.
 from tkinter import*
import tkinter

def widget_Tk(buttonpress):
    master=Tk()
    master.title("Click Widget")
    master1.destroy()
    
master1=Tk()
master1.title("Main Widget")
master1.bind("<ButtonPress>", widget_Tk)

master1.mainloop()








tkinter.Tk.destroy
The method  Erase text, delete Entry, and destroy the widget() through Button(command) throug default setting.
from tkinter import*

master=Tk()

def e1_delete():
    e1.delete(first=0,last=100)

def master_destroy():
     master.destroy()
    

def entry_destroy():
    e1.destroy()
    

e1=Entry(master, width=35)
e1.pack()


b_erase=Button(master, text="Erase", command=e1_delete)
b_erase.pack()

b_quit_destroy=Button(master, text="Quit", command=master_destroy)
b_quit_destroy.pack()


b_delete_text=Button(master, text="Delete Entry", command=entry_destroy)
b_delete_text.pack()


master.mainloop()


 






Comments