问题描述
我正在尝试使用pygame检索在显示器上绘制的颜色,但似乎无法使用它。我拿出了一些无关的代码以便于阅读,但这就是我的意思。
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'
推荐答案
setDisplay
是您创建的变量,而不是 p上的属性ygame
。仅尝试 setDisplay.get_at((20,20))
。我不确定为什么甚至要使用描述符,看来您应该在 pygame.setDisplay AttributeError
$ c>甚至没有调用 get_at
描述符,但是无论如何,您应该在 setDisplay
上调用它,不能取消 pygame
的属性。
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
.
这篇关于无法使pygame.Surface.get_at()正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!