Tkinter question: position cursor within text widget

Fredrik Lundh fredrik at pythonware.com
Sun Jan 5 16:39:59 CET 2003


"v.wehren" <v.wehren at home.nl> wrote:

> After loading the contens of a text file into a text widget with something
> like: <snip>
>      content = inf.read()
>      self.textbox.insert(END, content)
>      self.textbox.focus_set()
>       </snip>
>
> I want the insert cursor to be at the home position after the file has
> loaded.Is there a simple method to position the cursor at a given index? I
> haven't *found* any in the "prevailing" Tkinter sources across the web
> yet...

the cursor is represented by a predefined mark called INSERT.  to
move it around, use the mark_set method:

    self.textbox.mark_set(INSERT, 1.0)

more information here:

    http://www.pythonware.com/library/tkinter/introduction/text.htm
    (click on "Concepts" and scroll down to "Marks")

</F>






More information about the Python-list mailing list