Tkinter में, कभी-कभी, हम टेक्स्ट विजेट को अक्षम करना चाह सकते हैं। इसे प्राप्त करने के लिए, हम टेक्स्ट कॉन्फ़िगरेशन को अक्षम के रूप में सेट कर सकते हैं। यह टेक्स्ट विजेट को फ्रीज कर देगा और इसे केवल पढ़ने के लिए बना देगा।
इस उदाहरण में, हम एक टेक्स्ट विजेट और एक बटन बनाएंगे जो उपयोगकर्ताओं को टेक्स्ट विजेट को तुरंत अक्षम या फ्रीज करने की अनुमति देगा।
उदाहरण
#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():
text.config(state= DISABLED)
#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= "Disable", command= disable_button,fg= "white",
bg="black", width= 20).pack(pady=20)
win.mainloop() आउटपुट
उपरोक्त कोड को चलाने से एक टेक्स्ट विजेट और एक बटन बन जाएगा जिसका उपयोग विजेट को अक्षम या फ्रीज करने के लिए किया जा सकता है।

आपके द्वारा "अक्षम करें" बटन पर क्लिक करने के बाद, टेक्स्ट विजेट अक्षम हो जाएगा और आप इसके अंदर कुछ और टाइप नहीं कर पाएंगे।