How can I insert a string in an Entry widget that is in the "readonly" state using Tkinter?

Tkinter Entry widget is used to insert single-line text input. We can use the Entry widget to create forms where single-line input is the prime requirement.

Sometimes, we need to insert a predefined text inside the Entry Widget. In such cases, we can use insert(INSERT,) method. These are generally called as Placeholders for the Entry widget.

Let us suppose that we want to change the state of our text as read-only. Here, we can use state= ‘readonly’ property while configuring the Entry widget.

Example

#Import the required Libraries
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame
win = Tk()
#Set the geometry of tkinter frame
win.geometry("750x270")
#Create an Entry Widget
entry= ttk.Entry(win, width= 40)
entry.insert(0, 'www.tutorialspoint.com')
#Set the state of Entry widget ReadOnly
entry.configure(state= "readonly")
entry.pack(ipadx= 20,ipady=10)
win.mainloop()

Output

Running the above code will display a window that will have an Entry widget containing a single text which cannot be modified.

Updated on: 2021-05-03T08:58:54+05:30

969 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements