I have multiple Tkinter listboxes that I have scrolling together using a single scrollbar, but I'd ALSO like them to scroll together for mousewheel activity over any of the listboxes.
How to do this?
My current code is based on the last pattern discussed here: http://effbot.org/tkinterbook/listbox.htm It works fine when using only the scrollbar, but the listboxes scroll independently when the mousewheel is used.
I know this is pretty old, but I think the solution is a bit more simple than those proferred here. Assuming that you always 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.
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:
Here's my current solution, coded as a stand-alone function (yes, it should be an object).
Features/requirements:
Code:
Suggestions for improvements are welcome!
Solve the problem pretty much the same way as you did to connect the two widgets to a single scrollbar: create custom bindings for the mousewheel and have those bindings affect both listboxes rather than just one.
The only real trick is knowing that you get different events for the mousewheel depending on the platform: windows and the Mac gets
<MouseWheel>
events, linux gets<Button-4>
and<Button-5>
events.Here's an example, tested on my Mac with python 2.5: