Search code examples
pythonpython-3.xtkintertkinter-entry

Keeping the Insertion Cursor on a readonly Tkinter Entry


I am using the tkinter module in my python code to create my gui for an simple app I am creating. I was wondering if it is possible to keep the insertion cursor visible even when the the state on my entry widget is set to "readonly". I want the user to still see where the insertion cursor is in the text but not be able to edit the text directly using the keyboard.


Note:

When I say Insertion Cursor I don't mean the normal mouse cursor/pointer but the flashing bar which shows up on text which you can edit. I'm not sure what the proper name for it is... Below is an example of what I mean (the black bar in the Entry)

Example of insertion cursor


I have tried setting the 'insertwidth' and other insertion cursor config options in the Entry widget to see if the cursor was perhapes just hidden but it did not work.

Any help is appreciated.

Thanks!


Solution

  • Instead of making the entry widget readonly, you could block all keyboard events on the widget, which makes typing in it impossible:

    entry.bind("<Key>", lambda e: "break")