Pygame - 加载光标



Pygame 允许你控制系统光标。Pygame 只可以使用黑白光标。pygame.cursors 模块定义了预定义的光标枚举。

  • pygame.cursors.arrow
  • pygame.cursors.diamond
  • pygame.cursors.broken_x
  • pygame.cursors.tri_left
  • pygame.cursors.tri_right

箭头光标是默认选择。要使用其他光标,我们使用 pygame.mouse 模块中的 set_cursor() 函数。

pygame.mouse.set_cursor(pygame.cursors.broken_x)

示例

在下面的示例中,此光标可以在显示窗口中看到。

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)

输出

Display Windows

此模块还包含一些格式化为字符串的光标。要使用它们,请使用 pygame.cursors.compile() 函数。

  • 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)
广告