Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 817
sixglazed Avatar asked Feb 13 '13 05:02

sixglazed


People also ask

What entry widget method places text into the widget?

Summary. Use the ttk. Entry widget to create a textbox. Use an instance of the StringVar() class to associate the current text of the Entry widget with a string variable.

Which widget is used to accept the text strings from the user?

The Entry widget is used to accept single-line text strings from a user.

How do I make a textbox readonly in Python?

Text. insert(position, text, taglist) to add it to your readonly Text box window under a tag.


2 Answers

Use -textvariable option of the Entry:

eText = StringVar()
e = Entry(rootWin, width=60, state="readonly",textvariable=eText)
....
eText.set("...I'm not inserted, I've just appeared out of nothing.")
like image 77
Anton Kovalenko Avatar answered Sep 22 '22 21:09

Anton Kovalenko


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()
like image 40
mgilson Avatar answered Sep 21 '22 21:09

mgilson