【问题标题】:how do i arrange contents in a file in alphabetical order [duplicate]如何按字母顺序排列文件中的内容[重复]
【发布时间】:2019-03-14 01:34:32
【问题描述】:

我有这个错误。

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

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

【问题讨论】:

  • 我无法完美显示代码,请多多包涵
  • 请给出一个有意义的主题,正确格式化代码并剪裁到相关部分(如果需要的话),将错误消息作为文本提供,而不是作为相关部分被裁剪的图像。
  • 我怀疑None 不是有效的字体名称。使用您要使用的字体名称。
  • @Hans-MartinMosner 这不是问题所在。使用None 会导致pygame 使用默认字体,所以可以使用。
  • @CurtisCrentsil 下面发布的答案有帮助吗?

标签: python pygame


【解决方案1】:

错误

pygame.error: 字体未初始化

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

一些修复

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

【讨论】:

  • @sloth 我对此表示怀疑,已修复。谢谢! :)
猜你喜欢
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 2015-04-07
  • 2016-07-01
  • 2021-03-14
  • 2017-08-20
  • 1970-01-01
  • 2014-12-21
相关资源
最近更新 更多