Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cursor position in a Text widget

Is it possible to set the cursor position in a Tkinter Text widget? I'm not finding anything terribly useful yet.

The best I've been able to do is emit a <Button-1> and <ButtonRelease-1> event at a certain x-y coordinate, but that is a pixel amount, not a letter amount.

like image 431
Wayne Werner Avatar asked Jul 09 '10 18:07

Wayne Werner


1 Answers

If "text", "line", and "column" are your text object, the desired text line and desired column variables are, respectively:

text.mark_set("insert", "%d.%d" % (line + 1, column + 1))

If you would not like to care about the line number... well, you have to.

Complete documentation at The Tkinter Text Widget.

like image 57
jsbueno Avatar answered Nov 12 '22 04:11

jsbueno