Tkinter Entry - Disable
Tkinter - Clear/Delete value in the Entry field
In Tkinter, you can disable an Entry widget so that user cannot enter a value in the Entry field.
To disable an Entry widget in Tkinter, call the configure() method on the Entry object and pass the value of "disabled" for state parameter, as shown in the following.
entry.configure(state="disabled")
where
- entry is our Entry widget that needs to be disabled.
In this tutorial, you will learn how to disable an Entry widget in Tkinter, with examples.
Examples
1. Disable Entry field
In this example, we create a basic Tk window with an Entry widget and button. By default the Entry widget is enabled. If user clicks on the Disable button, in the event handler function disable_entry(), we disable the Entry widget.
Python Program
import tkinter as tk
# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")
label = tk.Label(window, text="Enter input value")
label.pack()
# Function to disbale the Entry field
def disable_entry():
entry.configure(state="disabled")
# Create an Entry field
entry = tk.Entry(window)
entry.pack()
# Create a button
button = tk.Button(window, text="Disable", command=disable_entry)
button.pack()
# Run the application
window.mainloop()
Output
In Windows
In MacOS
Run the program. The Entry field is normal by default.
Click on the Disable button.
The Entry widget is disabled.
Summary
In this Python Tkinter tutorial, we have shown how to disable an Entry field in Tkinter, with examples.