Is there any way to make the Tkinter Entry widget so that text can be highlighted and copied, but not changed?
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)
tk.DISABLED
and disabled
would have a different behavior before trying it out. That's really not a nice design. Thanks! Edit: However, keyboard event handling seems to be limited in this mode. Ctrl + C for copy only works at the first time. –
Beater disabled
. This might be by the design of Tkinter ... sorry for the confusion! –
Beater © 2022 - 2024 — McMap. All rights reserved.