टिंकर का उपयोग करके एप्लिकेशन बनाना आसान है लेकिन कभी-कभी, टाइटल बार पर बटन के माध्यम से विंडो या फ्रेम को बंद किए बिना बंद करना मुश्किल हो जाता है। ऐसे मामलों में, हम .destroy() . का उपयोग कर सकते हैं विंडो बंद करने की विधि।
चूंकि टिंकर विशेषताएँ एक-दूसरे से स्वतंत्र होती हैं, इसलिए हम एक बटन का उपयोग करके विंडो को बंद करने के लिए एक अलग विधि बना सकते हैं।
उदाहरण
#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() आउटपुट
यदि हम उपरोक्त कोड चलाते हैं, तो यह निम्न आउटपुट विंडो उत्पन्न करेगा -
