首页 > 解决方案 > 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()

标签: pythonpygame

解决方案


首先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()

推荐阅读