index in Tkinter text objects

Fredrik Lundh effbot at telia.com
Sat Sep 2 12:39:04 CEST 2000


Keagan Schopfer wrote::
> i am building a text editor using Tkinter, and i am wondering how i would
> find the current index of the insert currsor in a Text dialog. is there some
> function like text.get_current_index()?

the insert cursor has a symbolic name (INSERT), which
you can use everywhere Tkinter expects a buffer index.

to get the current line/column, use text.index(INSERT)
(this returns a string).  an example:

    # get line/column
    index = text.index(INSERT)

    # convert index to integers
    row, column = map(int, string.split(index, "."))

also see:
http://w1.132.telia.com/~u13208596/tkintrobook/text.htm

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->




More information about the Python-list mailing list