Anyone know how I would set an image for the cursor in Pygame?

Recommended Answers

All 2 Replies

Here is an example ...

# PyGame example of how to change the mouse cursor

import pygame as pg

bgcolor = 255, 255, 255  # white

screen = pg.display.set_mode((600, 300))
pg.display.set_caption('testing a different cursor')
screen.fill(bgcolor)

# set the mouse cursor
# you can replace diamond with arrow, ball, broken_x, tri_left, tri_right
#pg.mouse.set_cursor(*pg.cursors.diamond)
pg.mouse.set_cursor(*pg.cursors.tri_right)

# you can print the tuples associated with a certain cursor
# if you can make any sense of it, then you can customize it
print pg.cursors.arrow
"""
output -->
((16, 16), (0, 0), (0, 0, 64, 0, 96, 0, 112, 0, 120, 0, 124, 0, 126,
0, 127, 0, 127, 128, 124, 0, 108, 0, 70, 0, 6, 0, 3, 0, 3, 0, 0, 0),
(64, 0, 224, 0, 240, 0, 248, 0, 252, 0, 254, 0, 255, 0, 255, 128, 255,
192, 255, 128, 254, 0, 239, 0, 79, 0, 7, 128, 7, 128, 3, 0))
"""

pg.display.flip()

# set up the event loop ...
running = True
while running:
    event = pg.event.poll()
    # quit when window corner x is clicked
    if event.type == pg.QUIT:
        running = False

thanks,but I meant actually setting an image for the cursor, life "mouse.bmp" or something like that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.