Re: scrolling more widgets with one scrollbar
Michael Lange <klappnase <at> web.de>
2011-02-03 17:55:40 GMT
Hi again,
Thus spoketh Michael Lange <klappnase <at> web.de>
unto us on Thu, 3 Feb 2011 11:56:35 +0100:
> I set up a minimal example that shows how to use this technique to set
> up modified key bindings that allow to scroll two text widgets
> synchronously with the Up and Down keys:
>
At a second glance my example isn't so nice either, because it does not
only sync the yview but also the cursor position, which is most likely
not wanted. However this can be easily fixed by restoring the "slave"
widget's cursor position with something like:
def down(event):
oldinsert = slave[event.widget].index('insert')
root.tk.call('tk::TextSetCursor', slave[event.widget],
root.tk.call('tk::TextUpDownLine', event.widget, 1))
slave[event.widget].mark_set('insert', oldinsert)
Doing this for lots of event sequences is quite a pita though, maybe
wrapping it like this is a bit better:
slave = {t1: t2, t2: t1}
def callback(textwidget, *args):
oldinsert = slave[textwidget].index('insert')
root.tk.call(*args)
slave[textwidget].mark_set('insert', oldinsert)
(Continue reading)