tkinter ব্যবহার করে একটি অ্যাপ্লিকেশন তৈরি করা সহজ কিন্তু কখনও কখনও, শিরোনাম বারের বোতামের মাধ্যমে এটি বন্ধ না করে উইন্ডো বা ফ্রেমটি বন্ধ করা কঠিন হয়ে পড়ে৷ এই ধরনের ক্ষেত্রে, আমরা .destroy() ব্যবহার করতে পারি উইন্ডো বন্ধ করার পদ্ধতি।
যেহেতু tkinter বৈশিষ্ট্যগুলি একে অপরের থেকে স্বাধীন, আমরা একটি বোতাম ব্যবহার করে উইন্ডোটি বন্ধ করার জন্য একটি পৃথক পদ্ধতি তৈরি করতে পারি৷
উদাহরণ
#Import the library
from tkinter import *
#Create an instance of window
win = Tk()
#Set the geometry of the window
win.geometry("700x400")
#Define a function to close the window
def close_win():
win.destroy()
#Create a label
Label(win, text="Click the button to Close the window",
font=('Poppins bold', 25)).pack(pady= 20)
#Create a Button
Button(win, text= "Close", font=('Poppins bold', 16),
command=close_win).pack(pady=20)
win.mainloop() আউটপুট
যদি আমরা উপরের কোডটি চালাই, তাহলে এটি নিম্নলিখিত আউটপুট উইন্ডো তৈরি করবে -
