Tkinter का उपयोग करके एप्लिकेशन बनाना आसान है लेकिन कभी-कभी, title bar पर button के बिना window या frame को close करना मुश्किल हो जाता है। ऐसे cases में, हम window close करने के लिए .destroy() method का उपयोग कर सकते हैं।
चूंकि tkinter attributes एक-दूसरे से independent हैं, हम button का उपयोग करके window close करने के लिए एक separate method बना सकते हैं।
उदाहरण
# 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()
आउटपुट
यदि हम उपरोक्त code चलाते हैं, तो यह निम्न output window produce करेगा:
