Search code examples
pythonpython-3.xpyglet

Setting mouse cursor in pyglet


I'm trying to set the mouse cursor in a pyglet application. According to the pyglet documentation, this is how I should go about this:

import pyglet

window = pyglet.window.Window()

cursor = window.get_system_mouse_cursor(win.CURSOR_HELP)
window.set_mouse_cursor(cursor)

pyglet.app.run()

However, this gives me the following error:

cursor = window.get_system_mouse_cursor(win.CURSOR_HELP)
NameError: name 'win' is not defined

How can I do this without using my own cursor image files? I'm on linux if that helps.


Solution

  • The CURSOR_HELP attribute is a member of your window class.

    Change

    win.CURSOR_HELP
    

    to

    window.CURSOR_HELP
    

    Found here: https://pyglet.readthedocs.io/en/pyglet-1.2-maintenance/api/pyglet/window/pyglet.window.Window.html#pyglet.window.Window.CURSOR_HELP