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

Python Tkinter Root Window से कैसे छुटकारा पाएं?

कभी-कभी, Tkinter एप्लिकेशन test करते समय, हमें Tkinter default window या frame को hide करने की आवश्यकता हो सकती है। हमारे Tkinter window को या तो hide करने या destroy करने के दो general methods हैं।

mainloop() Tkinter window को तब तक चलाता रहता है जब तक इसे external events द्वारा close नहीं किया जाता। Window को destroy करने के लिए हम destroy() callable method का उपयोग कर सकते हैं।

हालांकि, Tkinter window को hide करने के लिए, हम generally "withdraw" method का उपयोग करते हैं जिसे root window या main window पर invoke किया जा सकता है।

इस उदाहरण में, हमने एक text widget और एक button "Quit" बनाया है जो root window को immediately close कर देगा। हालांकि, हम screen पर display होने से बचने के लिए withdraw method का भी उपयोग कर सकते हैं।

उदाहरण

# Import the library
from tkinter import *

# Create an instance of window
win = Tk()

# Set the geometry of the window
win.geometry("700x400")

def disable_button():
    win.destroy()

# Create a Label
Label(win, text="Type Something", font=('Helvetica bold', 25), fg="green").pack(pady=20)

# Create a Text widget
text = Text(win, height=10, width=40)
text.pack()

# Create a Disable Button
Button(win, text="Quit", command=disable_button, fg="white", bg="black", width=20).pack(pady=20)

# win.withdraw()
win.mainloop()

उपरोक्त python code withdraw method का उपयोग करके root window को hide करता है। हालांकि, window को destroy करने के लिए, हम destroy method का उपयोग कर सकते हैं।

आउटपुट

Python Tkinter Root Window से कैसे छुटकारा पाएं?

जब आप Quit button पर क्लिक करते हैं, तो यह root window को hide कर देगा।

  1. Tkinter लेबल टेक्स्ट कैसे प्राप्त करें? Tkinter लेबल टेक्स्ट कैसे प्राप्त करें?

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

  1. Tkinter विंडो को अन्य विंडोज़ के ऊपर कैसे लाएं? Tkinter विंडो को अन्य विंडोज़ के ऊपर कैसे लाएं?

    जब भी हम कोई GUI प्रोग्राम बनाते हैं, तो Tkinter आमतौर पर आउटपुट स्क्रीन को बैकग्राउंड में दिखाता है। यानी, Tkinter प्रोग्राम विंडो को अन्य प्रोग्राम्स के पीछे प्रदर्शित करता है। Tkinter विंडो को दूसरों के ऊपर लाने के लिए, हमें attributes(-topmost, True) प्रॉपर्टी का उपयोग करना होगा। यह विंडो को सबस

  1. Python में Tkinter का उपयोग करके Title Bar Edit कैसे करें? Python में Tkinter का उपयोग करके Title Bar Edit कैसे करें?

    Tkinter एक window या frame बनाता है जो program execute करने के बाद दिखाई देता है। चूंकि Tkinter में सभी functions और modules independent हैं, हम window attributes को customize करने के लिए विशेष रूप से एक particular function का उपयोग कर सकते हैं। Tkinter हर एप्लिकेशन के लिए एक default root window बना