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

sixglazed picture sixglazed · Feb 13, 2013 · Viewed 18.2k times · Source

I am trying to obtain an Entry that starts with an ellipsis ....

Here was the code I tried:

e = Entry(rootWin, width=60, state="readonly")
e.insert(0, "...")

I think the error is occurring because I am trying to insert text after the object has been classified as readonly.

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

Answer

mgilson picture mgilson · Feb 13, 2013

This seems to work for me:

import Tkinter as tk

r = tk.Tk()

e = tk.Entry(r,width=60)
e.insert(0,'...')
e.configure(state='readonly')
e.grid(row=0,column=0)

r.mainloop()