Search code examples
pythonpython-3.xpyglet

Pyglet on_mouse_click not detected


I'm new to Pyglet, but I've messed with Pygame and JFrames before. I'm having trouble with the on_mouse_click() event for Pyglet. It doesn't seem to ever be called, though all the other events (including on_mouse_release and on_mouse_drag). I have all the events logged, so it shows me every event that occurs.

Here's a simplified version of what I'm doing:

import pyglet

window = pyglet.window.Window(width=640, height=480)
window.push_handlers(pyglet.window.event.WindowEventLogger())

label = pyglet.text.Label("Hello world", font_name="Times New Roman" ,
                          font_size=36, x=window.width // 2, y=window.height // 2, 
                          anchor_x="center, anchor_y="center")
@window.event
def on_mouse_press(x,y,button,mod):
    print("Button Pressed")

pyglet.app.run()

My version is python 3.6. I'm using the PyCharm IDE (I've also tested it through cmd), Pyglet 1.3.1, and I'm using Windows 10


Solution

  • I had the same problem with pyglet version 1.3.1, everything worked except the on_mouse_press() method, so i downgraded to version 1.3.0 and now everything works fine. You can specify the version you want to install with pip like so:

    pip install pyglet==1.3.0