Python 如何在pygame中获得像素的颜色值?

Python 如何在pygame中获得像素的颜色值?,python,pygame,Python,Pygame,我想得到一个像素的颜色值。我读过一些关于函数“pygame.Surface.get_at()”的文章。但是当我使用这个函数时,我得到了这个错误: Traceback (most recent call last): pygame.Surface.get_at(300, 200) TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'int' 这里有两个问题: get\u at需要一个

我想得到一个像素的颜色值。我读过一些关于函数“pygame.Surface.get_at()”的文章。但是当我使用这个函数时,我得到了这个错误:

Traceback (most recent call last):
pygame.Surface.get_at(300, 200)
TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'int'

这里有两个问题:

  • get\u at
    需要一个元组
    (x,y)
    ,因此您应该使用以下方法调用它:

    .get_at((300, 200))
    
  • 您应该提供要获取其像素颜色的曲面。大概是这样的:

    screen = pygame.display.set_mode((150, 50))
    ...
    screen.get_at((300, 200))
    
这有帮助吗?