如何按字母顺序排列文件中的内容

时间:2019-03-13 09:40:24

标签: python pygame

我有这个错误。

image

我尝试过此操作,但给我一个错误

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

1 个答案:

答案 0 :(得分:1)

错误

  

pygame.error:字体未初始化

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

一些修复

  1. 初始化pygame.init()
  2. 您在White函数中使用screen.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

out