Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Tkinter Window Close कैसे करें?

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 करेगा:

Tkinter Window Close कैसे करें?

  1. Tkinter विंडो को स्थिर आकार में कैसे सेट करें? Tkinter विंडो को स्थिर आकार में कैसे सेट करें?

    जब भी हम अपना Tkinter एप्लिकेशन चलाते हैं, तो यह एक निश्चित आकार की विंडो प्रदर्शित करता है (यानी, विंडो की चौड़ाई और ऊंचाई)। विंडो का आकार स्थिर या नॉन-रिसाइज़ेबल बनाने के लिए, हम resizable() मेथड का उपयोग करेंगे।आमतौर पर, यह मेथड दो मान लेता है, यानी विंडो की चौड़ाई और ऊंचाई। विंडो का आकार स्थिर ब

  1. Tkinter Buttons Dynamically Generate कैसे करें? Tkinter Buttons Dynamically Generate कैसे करें?

    इस लेख में, हम देखेंगे कि tkinter window में buttons dynamically कैसे create करें। Buttons dynamically create करने का मतलब है buttons और उनकी functionality को events add करके customize करना। पहले, हम notebook में tkinter library import करेंगे, फिर हम Button function का उपयोग करके एक instance बनाएंगे

  1. Tkinter का उपयोग करके Splash Screen कैसे बनाएं? Tkinter का उपयोग करके Splash Screen कैसे बनाएं?

    मान लीजिए हम tkinter का उपयोग करके splash screen बनाना चाहते हैं। Splash screen बनाने के लिए, हम नीचे दिए गए steps का पालन करेंगे: कुछ labels के साथ splash screen बनाएं। overrideredirect method का उपयोग करके splash screen को borderless बनाएं। मुख्य window के लिए एक function बनाएं जो splash screen क