কখনও কখনও, আমরা এমন একটি উইজেট সরাতে চাই যা অ্যাপ্লিকেশনটিতে কোন কাজে আসে না। আমরা .destroy ব্যবহার করে উইন্ডো বা ফ্রেম থেকে উইজেট মুছে ফেলতে পারি tkinter এ পদ্ধতি। এটির জন্য একটি ফাংশন সংজ্ঞায়িত করে এটি উইজেটে আহ্বান করা যেতে পারে।
উদাহরণ
এই উদাহরণে, আমরা একটি বোতাম তৈরি করেছি যা উইন্ডো থেকে টেক্সট লেবেল উইজেট সরিয়ে দেবে।
#Import the tkinter library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
#Set the geometry
win.geometry("650x450")
#Define a function to remove the text from the screen
def delete_text():
text.destroy()
#Create a text widget
text= Label(win,text="This is a New Line", font=('Aerial bold', 20))
text.pack(pady=20)
#Create a button for Deleting Widget
Button(win, text= "Click Here", font=('bold',20), command=
delete_text).pack(pady=10)
win.mainloop() আউটপুট
উপরের কোডটি চালানোর ফলে নিম্নলিখিত আউটপুট −
উৎপন্ন হবে

এখন, "এখানে ক্লিক করুন" বোতামে ক্লিক করুন। এটি উইন্ডো থেকে লেবেল টেক্সট উইজেট মুছে ফেলবে।
