agepy.interactive.coincedence.MouseEvent
- class MouseEvent(name, canvas, x, y, button=None, key=None, step=0, dblclick=False, guiEvent=None, *, buttons=None, modifiers=None)
Bases:
LocationEventA mouse event (‘button_press_event’, ‘button_release_event’, ‘scroll_event’, ‘motion_notify_event’).
A MouseEvent has a number of special attributes in addition to those defined by the parent Event and LocationEvent classes.
- Attributes:
- button
python:Noneor MouseButtonor{‘up’, ‘down’} The button pressed. ‘up’ and ‘down’ are used for scroll events.
Note that LEFT and RIGHT actually refer to the “primary” and “secondary” buttons, i.e. if the user inverts their left and right buttons (“left-handed setting”) then the LEFT button will be the one physically on the right.
If this is unset, name is “scroll_event”, and step is nonzero, then this will be set to “up” or “down” depending on the sign of step.
- buttons
python:Noneorfrozenset For ‘motion_notify_event’, the mouse buttons currently being pressed (a set of zero or more MouseButtons); for other events, None.
Note
For ‘motion_notify_event’, this attribute is more accurate than the
button(singular) attribute, which is obtained from the last ‘button_press_event’ or ‘button_release_event’ that occurred within the canvas (and thus 1. be wrong if the last change in mouse state occurred when the canvas did not have focus, and 2. cannot report when multiple buttons are pressed).This attribute is not set for ‘button_press_event’ and ‘button_release_event’ because GUI toolkits are inconsistent as to whether they report the button state before or after the press/release occurred.
Warning
On macOS, the Tk backends only report a single button even if multiple buttons are pressed.
- key
python:Noneorpython:str The key pressed when the mouse event triggered, e.g. ‘shift’. See KeyEvent.
Warning
This key is currently obtained from the last ‘key_press_event’ or ‘key_release_event’ that occurred within the canvas. Thus, if the last change of keyboard state occurred while the canvas did not have focus, this attribute will be wrong. On the other hand, the
modifiersattribute should always be correct, but it can only report on modifier keys.- step
python:float The number of scroll steps (positive for ‘up’, negative for ‘down’). This applies only to ‘scroll_event’ and defaults to 0 otherwise.
- dblclickbool
Whether the event is a double-click. This applies only to ‘button_press_event’ and is False otherwise. In particular, it’s not used in ‘button_release_event’.
- button
Examples
def on_press(event): print('you pressed', event.button, event.xdata, event.ydata) cid = fig.canvas.mpl_connect('button_press_event', on_press)
Methods