”;
Pygame can let you control system cursor. Onlu black and white cursors can be used in Pygame. The pygame.cursors module defines contain predefined cursor enumerations.
- pygame.cursors.arrow
- pygame.cursors.diamond
- pygame.cursors.broken_x
- pygame.cursors.tri_left
- pygame.cursors.tri_right
The arrow cursor is the default choice. To use another cursor, we use set_cursor() function in pygame.mouse module.
pygame.mouse.set_cursor(pygame.cursors.broken_x)
Example
In the following example, this cursor can be seen on the display window.
import pygame,sys from pygame.locals import * pygame.init() pygame.mouse.set_cursor(pygame.cursors.broken_x) canvas=pygame.display.set_mode((400,300)) pygame.display.set_caption("Cursor") while True: for event in pygame.event.get(): if(event.type == QUIT): pygame.quit() sys.exit(1)
Output
This module also contains a few cursors as formatted strings. To use them, use pygame.cursors.compile() function.
- pygame.cursors.thickarrow_strings
- pygame.cursors.sizer_x_strings
- pygame.cursors.sizer_y_strings
- pygame.cursors.sizer_xy_strings
- pygame.cursor.textmarker_strings
cursor = pygame.cursors.compile(pygame.cursors.textmarker_strings) pygame.mouse.set_cursor((10,10), (0, 0), *cursor)
Advertisements
”;