Pygame窗口挂起

时间:2013-02-06 01:59:48

标签: python pygame

我正在使用pygame做一个情节(我知道我可以使用matplotlib,但这更适合),情节渲染正确但pygame窗口挂起,代码有问题吗?

        xp,yp = 400,400
        pantalla = pygame.display.set_mode((xp,yp))
        pantalla.fill((255,255,255))
        for x in range(0,xp,20):
            pygame.draw.line(pantalla, (0,0,0) , (x, 1), (x, 800))
        for y in range(0,yp,20):
            pygame.draw.line(pantalla, (0,0,0) , (1, y), (800, y))
        pygame.draw.line(pantalla,(0,0,0), (yp/2,0),(yp/2,xp),4)
        pygame.draw.line(pantalla,(0,0,0), (0,xp/2),(yp,xp/2),4)
        pygame.draw.circle(pantalla, (0,0,0), (xp/2,yp/2),5)
        pygame.display.flip()
        #### La pantalla esta cargada totalmente a partir de aqui
        while 1:
            colora,colorb,colorc = random.randint(0,0),random.randint(0,0),random.randint(0,0)
            listacoordenadas = []
            for x in range(-6,7):
                listacoordenadas.append((x*20+xp/2,yp/2-eval(code)*20))
            for indice in range(len(listacoordenadas)-1):
                pygame.draw.line(pantalla,(colora,colorb,colorc), listacoordenadas[indice],listacoordenadas[indice+1],4)
            pygame.display.flip()
        raw_input()

1 个答案:

答案 0 :(得分:2)

你的问题很简单,你无法离开循环。将以下代码放在while 1:循环中的某个位置。另外,请记住import sys

for event in pygame.event.get():
    if event.type==pygame.QUIT:
        pygame.quit()
        sys.exit()