473,471 Members | 4,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TK binding mouse wheel scroll to scrolled list

ilikepython
844 Recognized Expert Contributor
I have a class that I use for a scrolled list. The problem is I want to be able to scroll the list using the mouse wheel. I am using bind and it's not working:
Expand|Select|Wrap|Line Numbers
  1. class ScrolledList(Frame):
  2.     def __init__(self, parent = None):
  3.         Frame.__init__(self, parent)
  4.         self.box = Listbox(self)
  5.         ... more code ...
  6.  
  7.         self.box.bind("<MouseWheel>", self.wheelscroll)
  8.  
  9.     def wheelscroll(self, event):
  10.         if event.delta > 0:
  11.             self.box.yview_scroll(-2, 'units')
  12.         else:
  13.             self.box.yview_scroll(2, 'units')
  14.  
I also tried binding to the Frame but that doesn't work. I think the problem is the box isn't getting the messages, but then what should I bind to? Also, If I don't bind to the box, what happens if I have more than one scrolled list in one frame?
Aug 21 '07 #1
3 5087
bartonc
6,596 Recognized Expert Expert
Hi John,

here is a code snippet I have successfully used:

self.canvas.bind('<4>', lambda event : self.canvas.xview('scroll', -1, 'units'))
self.canvas.bind('<5>', lambda event : self.canvas.xview('scroll', 1, 'units'))

or if you do not like the lambda, you can use a callback like this:

def rollWheel(event):
if event.num == 4:
self.canvas.xview('scroll', -1, 'units')
elif event.num == 5:
self.canvas.xview('scroll', 1, 'units')

I hope this helps
From mail.python.org/pipemail, June of '06.

Hope that helps.
Aug 21 '07 #2
ilikepython
844 Recognized Expert Contributor
From mail.python.org/pipemail, June of '06.

Hope that helps.
Well I found that same page too, but it turns out that button 4 and 5 work only on linux, and on windows you have to use the mousewheel event.
Aug 21 '07 #3
ilikepython
844 Recognized Expert Contributor
I figured it out. The problem was that the list box never got focus. I added this line and it worked:
Expand|Select|Wrap|Line Numbers
  1. self.box.bind("<Button-1>", lambda x: self.box.focus())
  2.  
Aug 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jack | last post by:
Gday everyone, I'm dearly hoping Stephen Lebans is going to update his masterpeice to stop the mouse wheel scrolling to work on subforms *he has indicated this to me but of course beggers can't...
1
by: jv | last post by:
I have quite a few of continuous form and subform where I do allow scroll bars. I run into problems with the mouse wheel whenever the data on the form does not take up the whole page. In this...
1
by: Marcin | last post by:
Im using MS Access 2000. i have a main form and ona subform that is scrolled vertically. unfortunately i use mouse scroll to scroll this subform. I appreciate your help
1
by: nicholas | last post by:
Hi, If on an asp.net page the user has just selected a value in a dropdownlist and scrolls with the wheel of his mouse, the selected value of the dropdownlist will change. How could I avoid...
7
by: tommaso.gastaldi | last post by:
This is a curious question. I'd like to know your opinion. I am attaching a drawing resize to a mouse wheel event. Frankly, to me was most natural that, if I mouse wheel UP, the shape gets...
2
by: Greg | last post by:
I need to prevent a combo box's contents from being scrolled using the mouse wheel. I've tried using an overridden combo box and ignoring the base call within protected override void...
14
by: effendi | last post by:
Is it possible for me to disable the wheel scroll in a mouse when user click on a drop-down list? Thanks
1
by: kallol | last post by:
I have a simple HTML page where I have a form with in a <div style="height: 600px; width: 100%; overflow: auto;">. The mentioned div styles are mandatory to get the expected behavior of the div. ...
2
by: wpollans | last post by:
Hello, I need to able to write JS that will click on a link with the middle mouse button - so that the link target will open in a new window or tab - using firefox. Or is there a better (more...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.