Tkinter ->> selected mouse text

Fredrik Lundh fredrik at
Mon Jun 9 15:43:22 CEST 2003

jubafre at wrote:

> how can i get a selected text with the mouse in a
> text componnent in tkinter?? i have to get start
> position and end position of the selected text.

what's a text component?  a Text widget?  if so, use the
SEL_FIRST and SEL_LAST indices:

    s = text.get(SEL_FIRST, SEL_LAST)

if you need the actual row/column coordinates, use the
index method to get a "row.column" index:

    first = text.index(SEL_FIRST)
    last = text.index(SEL_LAST)

for more info, see "concepts" and "patterns" under:


More information about the Python-list mailing list