1

I have created these two functions :The first increases the extent value of arc and the other decreases it. I tried binding them resp. to <MouseWheel> and <ShiftMouseWheel>. But it doesn't work.

def angle_up(event= None):
    global extent
    extent += 2

def angle_dn(event= None):
    global extent
    extent -= 2

Then I bound them to mouse events:

def draw_arc(event=None):
    frame.bind('<MouseWheel>',angle_up)
    frame.bind('<Shift-MouseWheel>', angle_dn)

Even if I scroll the wheel down the angle_dn function doesn't gets called, instead the angle_up function gets called.

Is there any way to bind mousewheel upwards motion to a separate function and downwards movement of wheel to a separate function?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Does this answer your question? [Python tkinter binding mousewheel to scrollbar](https://stackoverflow.com/a/17457843/7414759) – stovfl Jun 05 '20 at 16:29
  • No , I've already read that one.If we bind MouseWheel to scrollbar that different i.e., it goes down on downwards motion of scrollwheel and vice versa.As I stated above, in case of binding it to normal functions it behave differently. My struggle is to bind different functions to wheel movement depending on its direction upwards & downwards. – atta ul momin Jun 05 '20 at 16:49
  • 1
    Read up on [Events and Bindings](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm), Section **Event Attributes** using `event.num` to distinguish between **up** and **down**. Read the last answer of the given link. – stovfl Jun 05 '20 at 17:17

1 Answers1

0

Tkinter's event has an attribute delta which returns a positive integer when scrollwheel moves up and vice versa.
Instead of creating two separate functions ,create a new function angle having an argument event.

def angle(event):
    if event.delta > 0:
        extent += 1
    elif event.delta < 0:
        extent -= 1

Bind this function to <MouseWheel> event.

cavas.bind("<MouseWheel>" , angle)

Moving ScrollWheel upwards will increment extent and downwards motion will decrement extent