473,382 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

TK binding mouse wheel scroll to scrolled list

ilikepython
844 Expert 512MB
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 5072
bartonc
6,596 Expert 4TB
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 Expert 512MB
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 Expert 512MB
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.