首页 > 解决方案 > 如何按字母顺序排列文件中的内容

问题描述

我有这个错误。

图片

我试过了,但它给了我一个错误

import time
import pygame


screen = pygame.display.set_mode((500,500))
red= (255,0,0)
black =(0,0,0)
white =(255,255,255)

EXIT= False
font = pygame.font.SysFont(None, 25)

def alert(msg,color):
    text = font.render(msg,True,color)
    screen.blit(text,[250,300])

while not EXIT:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.QUIT:
                EXIT =True

    screen.fill(White)
    pygame.display.update()
alert("TESTING ALERT 1,2,3",red)

pygame.display.update()
time.sleep(3)
pygame.quit()
quit()

标签: pythonpygame

解决方案


错误

pygame.error:字体未初始化

我几乎无法从您附加的图像中读取错误。

几个修复

  1. 初始化pygame.init()
  2. Whitescreen.fill()函数中使用,应该white改为。

因此

import time
import pygame

pygame.init()   #  initialize the pygame modules
screen = pygame.display.set_mode((500,500))
red = (255,0,0)
black = (0,0,0)
white = (255,255,255)

EXIT= False
font = pygame.font.SysFont(None, 25)  

def alert(msg,color):
    text = font.render(msg,True,color)
    screen.blit(text,[250,300])

while not EXIT:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.QUIT:
                EXIT =True

    screen.fill(white)     # Notice the case sensitivity
    pygame.display.update()
alert("TESTING ALERT 1,2,3",red)

pygame.display.update()
time.sleep(3)
pygame.quit()

输出

pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html

出去


推荐阅读