

See Projecting mouse position onto a given See the Web VPython example MousePicking.įrom the camera in the direction of the mouse cursor. You can test for a curve object with if instanceof(obj, curve). For curve objects, obj.segment is the number of the picked segment along the curve, starting with 1 (representing the segment from point number 0 to point number 1). At present label and helix cannot be picked. For example, the curves, spheres, and arrows created by make_trail, attach_trail, and attach_arrow are not pickable, and you may wish to specify that some of your own objects are not pickable. Also, obj will be None if the object has the pickable attribute set to False. If there is no object pointed to by the mouse, obj is None. If you have a box named B, you can determine whether the picked object is that box by asking if (B = obj). Pick Execute obj = to obtain the object pointed to by the mouse. Mouse information onto a given plane for other options.) VPythonĪlways chooses a point in the plane parallel to the screen and passing through scene.center. The object scene.mouse contains lots of information about the current state of the mouse, which you can interrogate at any time: Print('You pressed the mouse button at', ev.pos)

The package of information about the event that caused the end of the wait includes the information of whether it was a mouse or keyboard event: However, anonymous functions cannot be used in VPython 7. For examples, see the mouse drag discussion.

It is possible to use "anonymous" (unnamed) functions in this situation. Note that is true if the shift key is down at the time of the keyboard event similarly for and. You can bind events on different canvases to the same function and be able to tell in which canvas the event occurred. The quantity ev.canvas is the canvas associated with the event. The quantity ev.key is the corresponding character string, such as 'a' or 'delete'. For example, ev.which is 65 for the 'a' key.
#TKINTER GET MOUSE COORDINATES ON CANVAS CODE#
The quantity ev.which is the numerical key code or mouse button indicator (mouse button is always 1 for now). The quantity ev.event will be 'keydown' if a key was pressed or 'mousedown' if the left mouse button was pressed. The following will display the type of event (mouse click or keydown) and, in the case of a keydown event, which key is involved (see further details below): You can set up a function to be called when a mouse or keyboard event occurs. Scene.waitfor('click keydown') # click or keyboard Scene.waitfor('keyup') # wait for keyboard key release Scene.waitfor('keydown') # wait for keyboard key press Scene.waitfor('mousedown mousemove') # either event Scene.waitfor('mouseleave') # when leave canvas Scene.waitfor('mouseenter') # when move into canvas Scene.waitfor('mousemove') # wait for mouse to be moved Scene.waitfor('mouseup') # wait for mouse button release Scene.waitfor('mousedown') # wait for mouse button press Scene.waitfor('click') # wait for mouse button click Print(ev.pos) # the position of the mouse The package of information about the event includes information of what kind of event it was (see further event details below): You can use the package of information contained in the variable "ev": You can also obtain detailed information about the event: You can show a message to the user on the canvas: scene.pause('Click to proceed'). Scene.pause() An icon is displayed in the canvas to indicate a pause, waiting for a mouse click. Here is the simplest mouse interaction, which displays an icon and waits for a mouse click (the left mouse button going down and up)::
