You can store the current position of the mouse to check where on the 
screen it is to do checks, here's an example:

class Test(pyglet.window.Window):
    def __init__(self):
        super(Test, self).__init__(640, 480, resizable=False, fullscreen=
False, caption="Test")
        self.clear()

    #mouse cursor position
        self.mouse = [0,0]
    #button image
        self.button = pyglet.image.load('button.png').get_texture()
    #buttons x/y position
        self.button_pos = [320,240]

        pyglet.clock.get_fps()
        self.fps_display = pyglet.clock.ClockDisplay()

        pyglet.clock.schedule_interval(self.update, .01)


#update state
    def update(self,dt):
    #has the left mouse button has been released?
        if 'LEFT release' in self.mouse:
        #if the mouse is within the horrizontal bounds of the button
            if self.mouse[0] > self.button_pos[0] and self.mouse[0] < self.
button_pos[0] + self.button.width:
            #if the mouse is within the vertical bounds of the button
                if self.mouse[1] > self.button_pos[1] and self.mouse[1] < 
self.button_pos[1] + self.button.height:
                    print "Left button pressed!"
            

    #purge mouse button presses
        if len(self.mouse) > 2:
            while len(self.mouse) > 2:
                self.mouse = self.mouse[:2]

    #draw screen
        self.draw()


#draw the button
    def draw(self):
        self.clear()
        self.button.blit(self.button_pos[0], self.button_pos[1])
        self.fps_display.draw()


#Store the mouses current position
    def on_mouse_motion(self,x,y,dx,dy):
        self.mouse[0] += dx
        self.mouse[1] += dy

#capture mouse clicks
    def on_mouse_release(self,x,y,button,modifiers):
        self.mouse.append(mouse.buttons_string(button) + " release")



-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to