Tkinter question: position cursor within text widget

v.wehren v.wehren at home.nl
Sun Jan 5 13:39:32 EST 2003


Fredrik,

I tried that, and this works (although I thought it didn't, hence my
post..). But my guess is I have to *workaround* a different problem (sorry I
didn't catch it as such at first): What happens is that INSERT is set to the
mouse cursor position when I open the infile from an
tkFileDialog.askopenfile (on win32), by double-clicking the file name. The
open file ialog may namely overlap the textbox (depending on the position of
the main window). So when I *double-click* the file name to open a file, it
propably also triggers a mouse click at the underlying textbox position
setting the insert cursor to the CURRENT mark. My guess ís to workaround
this I have to fire mark_set(INSERT, 1.0) from a virtual event again under
this condition...(?)

Vincent Wehren
















"Fredrik Lundh" <fredrik at pythonware.com> schrieb im Newsbeitrag
news:jlYR9.4678$LY2.268521 at newsc.telia.net...
> "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