你好,我在尝试运行函数时经常遇到这个错误, 选一种颜色在这种情况下它是粉红色的。你知道吗
import pygame
导入系统 导入菜单 导入RGB颜色 从pygame.本地人导入* 从rgbcolors导入rgbcolor
def main():
# start screen
pygame.init()
screen1 = pygame.display.set_mode((500, 400))
# Fill background
background = pygame.Surface(screen1.get_size())
pygame.draw.line(screen1, (255, 0, 0), (230, 230), (100, 211), 4)
background = background.convert()
background.fill((0, 0,0))
# Displaying text
font = pygame.font.Font(None, 36)
text = font.render("Alien", 23, ((rgbcolor(pink))))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
screen1.blit(background, (0, 0))
pygame.display.flip()
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
screen1.blit(background, (0, 0))
pygame.display.flip()
pygame.time.get_ticks()
if __name__ == "__main__":
main()
这是我的rgbcolor函数。你知道吗
def rgbcolor(color):
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
darkBlue = (0, 0, 128)
white = (255, 255, 255)
black = (0, 0, 0)
pink = (255, 200, 200)
pass
错误代码。你知道吗
C:\Python27\python.exe C:/Users/Peter/PycharmProjects/game1/game.py
Traceback (most recent call last):
File "C:/Users/Peter/PycharmProjects/game1/game.py", line 44, in <module>
main()
File "C:/Users/Peter/PycharmProjects/game1/game.py", line 27, in main
text = font.render("Alien", 23, ((rgbcolor(pink))))
NameError: global name 'pink' is not defined
Process finished with exit code 1
试试这个:
相关问题 更多 >
编程相关推荐