为了账号安全,请及时绑定邮箱和手机立即绑定

“pygame.Surface”对象的描述符“get_at”不适用于“元组”对象

“pygame.Surface”对象的描述符“get_at”不适用于“元组”对象

12345678_0001 2023-03-16 17:16:03
我正在创建一个程序,如果光标位置的像素还不是黑色,我会尝试在光标位置绘制一个矩形。if pygame.Surface.get_at(pygame.mouse.get_pos()) != (0,0,0,255):    pygame.draw.rect(win, (0,0,0), (x, y, 3, 3))当我尝试实现 pygame.Surface.get_at() 时发生错误,它说...TypeError: descriptor 'get_at' for 'pygame.Surface' objects doesn't apply to a 'tuple' object.. 即使 pygame.Surface.get_at() 在https://pygame.org上的文档显示该方法的输入应该是一个元组。get_at()    get the color value at a single pixel    get_at((x, y)) -> Color    Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then     the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface     an IndexError exception will be raised.我怎样才能解决这个问题?
查看完整描述

1 回答

?
一只甜甜圈

TA贡献1836条经验 获得超5个赞

您需要调用get_atpygame.Surface 对象,而不是类本身。



screen = pygame.display.set_mode(size)


pixel = screen.get_at(pygame.mouse.get_pos()) #gets the pixel on the screen surface


another_surface = pygame.Surface((100, 100))


another_pixel = another_surface.get_at((50, 50)) #gets the pixel from the 'another_surface' surface




查看完整回答
反对 回复 2023-03-16
  • 1 回答
  • 0 关注
  • 303 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号