Can't get pygame.Surface.get_at() to work properly

馋奶兔 提交于 2019-12-25 03:58:14

问题


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:


setDisplayis 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!