Skip to content Skip to sidebar Skip to footer

Python - How To Get Cursor Position In Tkinter Text Widget

I want to get the cursor position (line and column) of the insertion point of a Tkinter.Text, but for the specific situation below. PROBLEM: My text editor project requires a cust

Solution 1:

I finally figured out what was going on and has nothing to do with Tkinter, but all Toolkits. I can now honestly say that I can add something to Best Programming Practices and :

Do Not Process Key Events by Binding to a Key Release Method, Instead Process Keys with a Key Press Method

Why?

It's not really a programming issue, it's a hardware issue. When a key is pressed, the physical key goes down. There is a spring that pushes the key back up. If that spring or anything about your keyboard causes a key to be even 200ths of second slower, typing even 60 words a minute may cause keys that were typed in one order to come back in another order. This may happen because a spring may be slightly thicker, stiffer, over used, or even sticky mocha cause more resistance.

Capitalization can be affected as well. Pressing the shift key and another key to get an upper case must be simultaneously pressed down. But if you process keys on key release, it is possible the shift key springs up faster than the character key you are capitalizing, which will result in a lower case. This also allows characters to be inverted. If you check on positions of a character when it's typed, you can get the wrong position due to this as well.

Stick with Key Press.

Post a Comment for "Python - How To Get Cursor Position In Tkinter Text Widget"