[Tkinter-discuss] Where am I in a scrolled Text()?

Michael Lange klappnase at web.de
Thu Feb 28 00:33:28 CET 2013


Hi,

On Wed, 27 Feb 2013 14:35:11 -0800
Lion Kimbro <lionkimbro at gmail.com> wrote:

> Perhaps use window coordinates?
> 
> There's a way of indexing with "@x,y" that might work.
> 
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-index.html
> https://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M20

yes, something like this might do the trick:

from Tkinter import *
from ScrolledText import ScrolledText

root = Tk()
text = ScrolledText(root)
text.pack(side='left', fill='both', expand=1)
f = open('/etc/fstab', 'r')
text.insert('end',f.read())
f.close()

def test(ev):
    y0, y1 = text.yview()
    print text.index('@0,%d' % y0)

root.bind('<F1>', test)
root.mainloop()

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Even historians fail to learn from history -- they repeat the same
mistakes.
		-- John Gill, "Patterns of Force", stardate 2534.7


More information about the Tkinter-discuss mailing list