无法正确使用pygame.Surface.get_at()

0 投票
1 回答
4080 浏览
提问于 2025-04-18 13:35

我正在尝试用pygame获取我在显示器上绘制的颜色,但我似乎无法做到这一点。为了让阅读更简单,我去掉了一些不相关的代码,这里是我现在的代码。

import pygame
import sys
from pygame.locals import *

pygame.init()

blue = (0,0,255)

#sets up screen
setDisplay = pygame.display.set_mode((400,400))
pygame.display.set_caption('Connections')

pygame.draw.circle(setDisplay, blue, (20,20), 10, 10)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()

    print pygame.setDisplay.get_at((20,20))

每次我运行这段代码时,都会出现以下错误:

TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'tuple'

1 个回答

1

setDisplay是你自己创建的一个变量,而不是pygame里的一个属性。你可以试试直接用setDisplay.get_at((20,20))。我不太明白你为什么会去用描述符,正常情况下在调用get_at之前,你应该会在pygame.setDisplay那里遇到一个AttributeError(属性错误)。不过无论如何,你应该是对你的setDisplay来调用,而不是去用pygame的属性。

撰写回答