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)
廣告
© . All rights reserved.