MouseWheel delta data type

I can read on this page, that the MouseWheel delta value data type is an integer. If it is an integer, why the people widely use this:

canvas.bind("<MouseWheel>", lambda event: canvas.yview_scroll(int( / 60), "units"))?

If the value is not an integer, or sometimes (on what occasions?), is it a float? Because if it would be a string, how you could divide the string by 60? Then I would recreate the code as follows:

canvas.bind("<MouseWheel>", lambda event: canvas.yview_scroll((int( / 60, "units"))

Or am I missing something?

I am sure someone that knows tk will know the answer.

But you can find out what the value is by printing its repr in the event handler. You would need to replace the lambda with a function to make that change.

Hi !

I’ve used the same resource for building Tkinter interfaces in the past. Did you read it thoroughly ?

In the .delta section, it clearly states that is a multiple of 120 on Windows, and can therefore always be divided by 60. On macOS, takes smaller values like 1 or 2, and should not be divided by 60. And on Linux, Button-4 and Button-5 should be used instead of the MouseWheel event.

Is there anything still unclear ?

I dont understand, but I guess I can print value type using type() method, If I were on Windows. But I dont have windows at the moment.

And does that paragraph say, what data type it is? I dont see it. Seeing placeholder “120” doesnt automatically mean, that its an integer data type.

For MouseWheel events, this attribute contains an integer whose sign is positive to scroll up, negative to scroll down

Cristal clear !

But I dont have windows at the moment.

Are you then using another OS ? Or just don’t have access to a computer RN ? If you’re using another OS then you don’t have to worry about division by 60.

I mean write this to find out what the is.

def eventHandler(event):
    print(‘event is’, repr(
    canvas.yview_scroll(( / 60), "units")

canvas.bind("<MouseWheel>", eventHandler)
1 Like

Yes you are right. The point was if this resource is a good resource of inofmation. So if the value is an integer for both Win and MacOS there is no need to change its data type then.

Yes, I am on Linux, but I have to worry If my code is cross platform I need to customize it for other platforms too.

Just checked a code where I manage mouse wheel events in a cross-platform compatible way, I just use something like:

In __init__:

if platform.system() == "Linux":
    self._canvas.bind('<4>', self._zoom)
    self._canvas.bind('<5>', self._zoom)
    self._canvas.bind('<MouseWheel>', self._zoom)

In _zoom:

if platform.system() == "Linux":
    delta = 1 if event.num == 4 else -1
    delta = int( / abs(

I then decide on the action to take based on the value of delta which is either 1 or -1 (zooming in or out of an image in my case).