pygame.mouse.set_cursor()简介

用于在GUI中设置当前光标样式,包括光标的形状、大小和热点(hotspot)位置。热点是光标上用于定位的点,通常是光标中心或其他特殊点。

语法:

pygame.mouse.set_cursor(hotspot:Tuple[int,int]|Sequence[int],surface:Surface)->None

pygame.mouse.set_cursor(size:Tuple[int,int]|Sequence[int],hotspot:Tuple[int,int]|Sequence[int],xormasks:Sequence[int],andmasks:Sequence[int])->None

pygame.mouse.set_cursor(constant:int)->None

pygame.mouse.set_cursor(cursor:Cursor)->None

  1. hotspotTuple[int,int]|Sequence[int];表示光标的热点位置。第一个整数是x坐标,第二个整数是y坐标。
  2. surfaceSurface;表示光标的图像数据。这个Surface对象应该包含光标的位图图像。
  3. size:Tuple[int,int]|Sequence[int];表示光标的大小。第一个整数是宽度,第二个整数是高度。
  4. xormasks:Sequence[int];用于定义光标的XOR位掩码。这些位掩码用于确定光标的形状和外观。
  5. andmasks:Sequence[int];用于定义光标的AND位掩码。这些位掩码用于确定光标形状中的透明区域。
  6. constant:int;表示预定义的光标样式。这些常量通常是系统特定的,用于选择标准的光标样式,如箭头、十字线等。
  7. cursor:Cursor(pygame.cursors.Cursor类);表示一个已经创建好的光标实例。你可以使用Cursor类来创建自定义的光标,并将其作为参数传递给set_cursor函数。

实例:

import pygame,sys
pygame.init()
pygame.display.set_mode((640,480))
imageUse=pygame.image.load("Usephoto.jpg")
imageWidth=imageUse.get_width()
imageHeight=imageUse.get_height()
print(f"photo's Width:{imageWidth}、height:{imageHeight}")
num=0
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type==pygame.MOUSEBUTTONDOWN:
            if num==0:
                # 使用pygame.mouse.set_cursor(hotspot:Tuple[int,int]|Sequence[int],surface:Surface)->None语法
                pygame.mouse.set_cursor([imageWidth//2,imageHeight//2],imageUse)
                num+=1
            elif num==1:
                # 使用pygame.mouse.set_cursor(constant:int)->None语法
                pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)
                num=0

备注:

先简介了两种方法,剩余两种暂时还未弄明白,随时重新编辑。

图片:

"./Usephoto.jpg"

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萧炎火

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值