Henry要努力 2021-10-06 13:23 采纳率: 0%
浏览 31

Python学习,根据书《Python编程:从入门到实践》学习,为啥不变颜色,理论上应该是灰色,但是它不变色,是黑色




```import pygame
def run_game():
    pygame.init()
    pygame.display.set_caption("Alien Invasion")
    screen = pygame.display.set_mode((1200,800))
    bg_color = (230, 230, 230)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
                screen.fill(bg_color)
                pygame.display.flip()
run_game()
  • 写回答

1条回答 默认 最新

  • Python-ZZY 2021-10-06 13:31
    关注

    你打错了!代码缩进有问题

    import pygame
    def run_game():
        pygame.init()
        pygame.display.set_caption("Alien Invasion")
        screen = pygame.display.set_mode((1200,800))
        bg_color = (230, 230, 230)
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
            screen.fill(bg_color)
            pygame.display.flip()
    '''
    上面这两行缩进出问题了
    '''
    run_game()
    
    评论

报告相同问题?

问题事件

  • 修改了问题 10月6日
  • 创建了问题 10月6日