首页 > 解决方案 > Pygame 窗口没有响应但没有错误

问题描述

我最近开始学习 pygame,但我遇到了一个错误,显示 pygame 在一段时间后没有响应。如果有人能找到我的错误,那真的很有帮助!这是我的代码:

import pygame

pygame.init()

screen = pygame.display.set_mode((800,600))

pygame.display.set_caption("Space Invaders")

BLUE = (0, 0, 255)

def player():
    pygame.draw.rect(screen,BLUE,(200,150,100,50))
 
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
             
    screen.fill((0,0,0))
     
    pygame.display.update()

标签: pythonpygame

解决方案


尝试pygame.quit()在代码末尾添加 a:

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

pygame.display.set_caption("Space Invaders")

BLUE = (0, 0, 255)

def player():
    pygame.draw.rect(screen, BLUE, (200, 150, 100, 50))
 
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
             
    screen.fill((0,0,0))
     
    pygame.display.update()
pygame.quit()

推荐阅读