Reputation: 3
Is there a way to efficiently calculate the char position from an index in the Tk Text widget?
As example:
„This is a dummy text displayed in Tk Text“
Index 1.11 (the „d“) would translate to 11
Thanks a lot for feedback!
Upvotes: 0
Views: 392
Reputation: 385980
The method count
will return the number of characters or lines or indices between two indexes. The default is to return "indices" which might be what you want. The values you want are added as additional positional arguments.
The function returns a tuple with the number of elements requested. For example, requesting "chars" will return a tuple with one value representing the number of characters.
chars = text.count("1.0", "1.11", "chars")[0]
assert chars==11
These are the options:
Upvotes: 1