[Tkinter-discuss] Restoring scroll position in a scrolled text window
Michael O'Donnell
michael.odonnell at uam.es
Tue Mar 16 18:22:00 CET 2010
Hi all,
Under Windows with python 2.6.4 Tkinter 8.5
I am trying to find a way to restore exactly the same scroll
position in a scrolled text widget, after deleting all text and
re-inserting the same text.
Given a text widget in self.text, I can do the following:
# record the index of the top visible line in the text widget
topidx=self.text.index("@0,0")
# redraw the text
self.renew()
# Restore the scroll
self.text.see(topidx)
However, "see" does not put this line index at the top
of the text widget, but rather some number of lines below
(unless it was already visible, in which case it stays where it was)
Is there an easy way to put a definite line at the top of a scrolled
text widget?
I would use
self.text.yview(MOVETO, fraction)
...but I cannot find out at what fraction of the window this line is!
(my lines are of variable height, so I cannot simply multiply line height).
Any other ideas?
Mick
More information about the Tkinter-discuss
mailing list