Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this is pretty old, but I think the solution is a bit more simple than those proferred here. Assuming that you <strong>always</strong> want the listboxes to be in agreement, then the above two answers aren't even complete solutions - changing selection by means of the arrow keys will scroll one listbox but not the other.</p> <p>So, looking at the answers, I asked - why aren't they hooking the yscrollcommand callback instead of just sending it straight to the scrollbar? So, I did just that:</p> <pre><code>try: from Tkinter import * except ImportError: from tkinter import * class MultipleScrollingListbox(Tk): def __init__(self): Tk.__init__(self) self.title('Scrolling Multiple Listboxes') #the shared scrollbar self.scrollbar = Scrollbar(self, orient='vertical') #note that yscrollcommand is set to a custom method for each listbox self.list1 = Listbox(self, yscrollcommand=self.yscroll1) self.list1.pack(fill='y', side='left') self.list2 = Listbox(self, yscrollcommand=self.yscroll2) self.list2.pack(expand=1, fill='both', side='left') self.scrollbar.config(command=self.yview) self.scrollbar.pack(side='right', fill='y') #fill the listboxes with stuff for x in xrange(30): self.list1.insert('end', x) self.list2.insert('end', x) #I'm sure there's probably a slightly cleaner way to do it than this #Nevertheless - whenever one listbox updates its vertical position, #the method checks to make sure that the other one gets updated as well. #Without the check, I *think* it might recurse infinitely. #Never tested, though. def yscroll1(self, *args): if self.list2.yview() != self.list1.yview(): self.list2.yview_moveto(args[0]) self.scrollbar.set(*args) def yscroll2(self, *args): if self.list1.yview() != self.list2.yview(): self.list1.yview_moveto(args[0]) self.scrollbar.set(*args) def yview(self, *args): self.list1.yview(*args) self.list2.yview(*args) if __name__ == "__main__": root = MultipleScrollingListbox() root.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload