Neat trick: `n' listboxes scrolled with one scrollbar 
Author Message
 Neat trick: `n' listboxes scrolled with one scrollbar

I've just discovered a neat trick for making `n' listboxes scroll
together using just one scrollbar.  It requires writing your own
methods to be using instead of the `yview' and `set' methods usual
used in the Scrollbar `boilerplate'.  This requires the patch to
Tkinter.py what I posted earlier to get the Scrollbar.get() method
to work.

--8<--8<-- cut here --8<--8<--
class ListBoxTest(Frame):

  def yview(self, *args):
    apply(self.lb1.yview, args)
    apply(self.lb2.yview, args)

  def yset(self, *args):
    apply(self.sb.set, args)
    fraction = self.sb.get()[0]
    self.lb1.yview('moveto', fraction)
    self.lb2.yview('moveto', fraction)

  def createWidgets(self):

    self.top = Frame(self)
    self.top.pack({'expand': 1, 'fill': 'both'})

    self.listpane = Frame(self.top)
    self.listpane.pack({'expand': 1, 'fill': 'both', 'side': 'left'})

    self.lb1 = Listbox(self.listpane)
    self.lb1.pack({'expand': 1, 'fill': 'both', 'side': 'left'})

    self.lb2 = Listbox(self.listpane)
    self.lb2.pack({'fill': 'both', 'side': 'left'})

    self.sb = Scrollbar(self.top, {'relief': 'sunken', 'bd': 2 })
    self.sb.pack({'fill': 'y', 'side': 'right'})

    self.lb1['yscrollcommand'] = self.yset
    self.lb2['yscrollcommand'] = self.yset
    self.sb['command'] = self.yview
--8<--8<-- cut here --8<--8<--

This was my first real pit of Python/Tk code and it took some time to
figure out the `*args' part of the argument passing but it seems to
work ok and even makes sure that the other listboxes move in tandem
when one listbox is scrolled by having its selected item dragged.

Ray.
--
  Computing Officer, MRC Research Centre in Brain and Behaviour,
     Department of Experimental Psychology, Oxford University



Tue, 21 Apr 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Scrolling two listboxes with one scrollbar?

2. SYNCHRONIZED SCROLLING, or, ONE SCROLLBAR TO SCROLL 2CanvasesWindows

3. ListBox / ScrollBar: Fire Event on Scroll

4. help with scrolling two listboxes by the single scrollbar

5. Scrolling two different widgets will one scrollbar

6. Scroll multiple windows with one scrollbar ?

7. scrolling multiple windows with one scrollbar

8. Join several listboxes to one scrollbar...

9. One Scrollbar for two listboxes??

10. one scrollbar for two listboxes?

11. one scrollbar for two listboxes?

12. Multiple listbox control with one scrollbar

 

 
Powered by phpBB® Forum Software