python - pygame窗口永远加载
问题描述
我是 pygame 的新手,我只是想用它编写国际象棋代码,但是我在后台加载时遇到了麻烦我查阅了很多教程,我认为一切都很好,我在做什么花了这么多时间?
import pygame
pygame.init
#create the screen with 800 pixals width and 600 pixals hieght
screen = pygame.display.set_mode((800,600))
# Background
background = pygame.image.load("chessboard.png")
running = True
while running:
#RGB colors
screen.fill((234,0,0))
#background image
screen.blit(background,(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
解决方案
首先pygame.init
是没有函数调用。这个声明根本没有任何作用。您必须添加括号来调用init()
:
pygame.init()
此外,您错过了pygame.display.flip()
在主应用程序循环中更新显示():
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#RGB colors
screen.fill((234,0,0))
#background image
screen.blit(background,(0,0))
# update display
pygame.display.flip()
推荐阅读
- ruby-on-rails - action_mailer rspec 测试的存根模板视图?
- machine-learning - 基于序列数据的流失率预测
- unity3d - Oculus Unity VR - 单独的 UI 摄像头不工作
- docker - 即使在 ubuntu 18.04 上重新安装 docker 后,Docker 守护程序也没有启动
- java - 如何在单元测试期间将资源文件路径交换为测试文件?
- spartacus-storefront - 使用服务器端渲染 (SSR) 运行时,Spartacus API 调用返回 504(网关超时)
- html-agility-pack - 如何检查 html 页面中是否存在节点?
- sql-server - 这两个 MS 查询会给我相同的输出吗?
- python - 在 Flask Web 应用程序中创建状态
- java - 第一次调用 prepareStatement 可以正常工作,但第二次调用 java.sql.SQLException: Connection has already been closed