python - python 3.7 pygame错误“没有响应”使用工作
问题描述
我正在尝试在 python 中制作一个移动的宇宙飞船,但我收到一条错误消息,上面写着“没有响应”
import pygame
def player(x, y):
screen.blit(playerImg, (x, y))
pygame.init()
screen = pygame.display.set_mode((800, 600))
playerImg = pygame.image.load("spaceship.png")
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
playerX = 350
playerY = 500
playerX_change = 0
playerX -= 2
running = True;
while running:
screen.fill((255, 0, 0))
player(playerX, playerY)
playerX -= 1
pygame.display.update()
解决方案
您需要修复主循环以侦听系统事件。
试试这个代码:
running = True;
while running:
for events in pygame.event.get(): #get all pygame events
if events.type == pygame.QUIT: #if event is quit then shutdown window and program
pygame.quit()
sys.exit()
screen.fill((255, 0, 0))
player(playerX, playerY)
playerX -= 1
pygame.display.update()
推荐阅读
- python - 插入数据,然后合并 2 个数据帧
- javascript - 尝试在 chrome.cookies.getAll() 循环中过滤特定域
- python - 如何使用 pyrebase 删除用户帐户?
- android - 如何在android中的RX java中迭代大小为100的列表
- database - 创建 API 密钥的不同策略是什么
- http-status-code-404 - 在 WHMCS 中成功下订单后出现 404 页面错误
- angular - 角度检测单击组件内的任何链接
- vb.net - VB.NET 子字符串函数损坏
- javascript - Javascript:在加载页面几分钟后,HTTP GET 请求中出现错误 403
- r - 从字符年份中提取月份并在R中使用doy