Make Tkinter Entry widget readonly but selectable

Question:

Is there any way to make the Tkinter Entry widget so that text can be highlighted and copied, but not changed?

Asked By: rectangletangle

||

Answers:

Use the state option "disabled" (all lowercase):

Use this option to disable the Entry widget so that the user can’t
type anything into it. Use state=tk.DISABLED to disable the widget,
state=tk.NORMAL to allow user input again. Your program can also find
out whether the cursor is currently over the widget by interrogating
this option; it will have the value tk.ACTIVE when the mouse is over
it. You can also set this option to ‘disabled’, which is like the
tk.DISABLED state, but the contents of the widget can still be
selected or copied.


Old answer from 2010…

Use the state option "readonly":

state=
The entry state: NORMAL, DISABLED, or “readonly” (same as DISABLED, but
contents can still be selected and
copied). Default is NORMAL. Note that
if you set this to DISABLED or
“readonly”, calls to insert and delete
are ignored. (state/State)

Answered By: Mark
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.