tkinter textwidget problem

kib2 kib2 at
Fri Oct 3 17:05:11 CEST 2008

> Tk/Tkinter apparently considers the position 1.13 to be after the last
> word in the text. You get the same problem if you set the insertion
> point just after the word 'two' for example: text.index('insert')
> returns 1.7 and text.index('insert wordstart') returns 1.7 too...


> My solution would simply be to go back one character before asking the
> word start: text.index('insert - 1 chars wordstart') Don't know if
> that'll do what you want if there are spaces at the end of the text. And
> BTW, if you actually want the *last* word in the text, you may want to
> use text.index('end - 2 chars wordstart'). Here, you have to use '- 2
> chars' because end points to the first non-existent index (2.0 in your
> case...).

Good idea, it seems to work fine now.
See you.


More information about the Python-list mailing list