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?
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.
The Entry widget is used to accept single-line text strings from a user.
Text. insert(position, text, taglist) to add it to your readonly Text box window under a tag.
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.")
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With