问题
I am trying to retrieve the color I have drawn onto my display using pygame, but I can't seem to get it to work. I took out some irrelevant code for easier reading, but here is what I have.
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))
Whenever I run this code, I get the following error:
TypeError: descriptor 'get_at' requires a 'pygame.Surface' object but received a 'tuple'
回答1:
setDisplay
is a variable you created, not an attribute on pygame
. Try just setDisplay.get_at((20,20))
. I'm not sure why you are even getting at the descriptor, it seems like you should be getting an AttributeError
on pygame.setDisplay
before even calling the get_at
descriptor, but in any case, you should be calling it against your setDisplay
, not off an attribute of pygame
.
来源:https://stackoverflow.com/questions/24789732/cant-get-pygame-surface-get-at-to-work-properly