Mouse Events: Mouse Clicked?

Skip to first unread message


Nov 19, 2010, 10:20:37 AM11/19/10
to NodeBox for OpenGL
Hello All!

It seems that this would be something that is simple to resolve, but I
was wondering if there is a simple way to create a "mouse clicked"
event in the canvas. I have been crawling through the nodebox/
graphics/ EventHandler class in order to figure out how
mouse events are currently handled, and at current (it seems) that
there are "pressed" and "dragged", and ways to access specific

I would like to be able to register a single click (i.e. mouse down,
mouse release) -- I must be overlooking something really obvious here,

Thanks _w

Tom De Smedt

Nov 19, 2010, 12:28:38 PM11/19/10
to NodeBox for OpenGL
You can use the on_mouse_release() event handler.
This event will fire after on_mouse_press(), if the mouse is still
inside the canvas/layer, when the mouse button is released. For layers
(e.g. a button), you may want to add an additional check to see if the
user has been dragging the layer (which is not a click event). The
example below illustrates this:

from import *

class Button(Layer):

color = Color(0,0,0,1)

def draw(self):
rect(0, 0, self.width, self.height)

def on_mouse_release(self, mouse):
if not self.dragged:
self.color = Color(random(), random(), random(), 1)
print "clicked",

b1 = Button(name="b1", width=100, height=100)
b2 = Button(name="b2", width=100, height=100, x=100, y=100)

A doubleclick is a bit more complicated (it requires a timer between
the two clicks). The Control class in gui/ has an
on_mouse_doubleclick() event which you can examine.


Nov 19, 2010, 11:38:20 PM11/19/10
to NodeBox for OpenGL
Thanks Tom -- This was very helpful!
Reply all
Reply to author
0 new messages