How to disable an entry widget in Tkinter
Overview
Tkinter is the standard GUI library for Python. We can create graphical applications using this library. In this Answer, we'll learn to disable an entry widget in Tkinter.
The entry widget is used to take input from the user. If we want to disable it, we need to pass disabled as a value to the state parameter in the config method.
Syntax
entry_widget.config(state="disabled")
Example
from tkinter import *
#get tinker instance frame
window = Tk()
#set window size
window.geometry("600x400")
#normal entry widget
entry=Entry(window, width= 30)
entry.pack(pady=20)
#disabled entry widget
entry_disabled=Entry(window, width= 30)
entry_disabled.pack(pady=20)
entry_disabled.config(state= "disabled")
window.mainloop()Explanation
- Line 1: We import everything from
tkinterpackage. - Line 4: We create an instance of the Tkinter frame and store it in the
windowvariable. We do so to keep widgets inside of the Tkinter frame in order to display them. - Line 7: We set the
windowsize of the Tkinter frame. - Line 11–12: We create the normal entry widget, with which users can interact.
- Line 15–17: We create the entry widget and disable it using the
configmethod and passdisabledas a value to thestateparameter.
After disabling, users won't be able to interact with the second entry widget.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved