You are comparing the button (the key-code) with the X/Y coordinates. This happens, because the function parameter button
shadows your global variable. Also, you should use the buttons x
, y
, width
and height
attributes.
button_texture = pyglet.image.load('button.png')
button_sprite = pyglet.sprite.Sprite(button_texture, x=135, y=window.height-65)
def on_mouse_press(x, y, button, modifiers):
if x > button_sprite.x and x < (button_sprite.x + button_sprite.width):
if y > button_sprite.y and y < (button_sprite.y + button_sprite.height):
run_program()
I renamed your global variable button
with button_sprite
to avoid the name collision.