python - 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()
解决方案
尝试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()
推荐阅读
- reactjs - 在 react-chartjs 中使用 html 元素作为图例
- symfony - Symfony 4.4:如何在 Bootstrap 模式中嵌入表单?
- ipv6 - CentOS 7 上的 Freeswitch 1.10:启动服务器时出错且没有用户注册
- node.js - 未捕获的 RangeError:长度错误!- 节点JS
- java - 多个绑定器无法在 Kubernetes 上使用 Spring-Cloud-Stream 和 Spring-Kubernetes
- python - 同一屏幕上的水平和垂直滚动视图kivy
- python - 没有名为“fbchat”的模块
- javascript - 将数字数组拆分为 9 个数组
- midi - 采用 n 个参数的纯数据抽象
- flutter - Flutter Drop DownMenuItem 小部件