This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Moving index with wordstart expression includes non-alphanumberic and underline characters if word is tagged and iat the edge of a text widget
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: 23412343214312, epaine, gpolo, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-09-30 18:28 by 23412343214312, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py 23412343214312, 2020-09-30 18:28 Short script which illustrates the issue
wordstart with tag.tcl epaine, 2020-10-01 11:23
Messages (3)
msg377716 - (view) Author: 23412343214312 (23412343214312) Date: 2020-09-30 18:28
This issue occurs when using the current mouse position from an event and the wordstart expression to find the index of the start of a clicked word on a text widget and the indices for the clicked word are tagged. If there's a single non-alphanumberic and underline character between the clicked word and the left edge of the text widget the index return for the start of the word will be the one for said non-alphanumeric and underline character. 

test.index(('@%s,%s wordstart' % (event.x, event.y)))

Assuming "[testing]" is at the indices 1.0 to 1.9 of a text widget, clicking on testing will return 1.1. If we tag the indices 1.1 to 1.8 with test.tag_add("tag", 1.1, 1.8) then clicking on the word testing will return 1.0. This change of return doesn't occur if "[testing]" does not begin at a x.0 index or if there's multiple non-alphanumeric and underline characters such as "[[testing]". Using wordend will return 1.8 in both tagged and non tagged scenarios.

The attached script illustrates this bug, only the middle text widget will print out the unexpected start index when clicking on the word testing. This issue isn't present when using python 3.5, running the script on python 3.5 will print out all expected indices.
msg377745 - (view) Author: E. Paine (epaine) * Date: 2020-10-01 11:23
Thank you for reporting this issue, however it is ultimately a Tk issue as shown by running the attached script in wish. I assume the Tk version was updated in Python 3.6, though I don't know which platform you are on so don't know which of Ned or Steve to nosy to verify this theory (you can check yourself by calling `tkinter.test.support.get_tk_patchlevel()` in both 3.5 & 3.6).

I am currently in the process of digging through the Tk source looking for the cause of the problem (so I can decide whether to report it to the Tk team - you can do so yourself if you prefer). This issue should be closed as third party, but I will link the Tk issue here if I decide to create one.
msg377751 - (view) Author: 23412343214312 (23412343214312) Date: 2020-10-01 13:26
I'm running on windows. The patch level on python 3.6 is (8, 6, 6, 'final', 0), while on python 3.5 is (8, 6, 4, 'final', 0).
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86062
2020-11-30 18:07:5323412343214312setstatus: open -> closed
resolution: third party
stage: resolved
2020-10-01 13:26:4023412343214312setmessages: + msg377751
2020-10-01 11:23:56epainesetfiles: + wordstart with tag.tcl

messages: + msg377745
2020-10-01 10:28:57epainesetnosy: + epaine
2020-09-30 18:28:1023412343214312create