python - 如何按字母顺序排列文件中的内容
问题描述
我有这个错误。
我试过了,但它给了我一个错误
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()
解决方案
错误:
pygame.error:字体未初始化
我几乎无法从您附加的图像中读取错误。
几个修复:
- 初始化
pygame.init()
- 您
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
推荐阅读
- java - Array(String[]) 中的 String 和 String 是不一样的,即使是
- html - 如何防止绝对定位的img移动
- vue.js - Vue + jest 调试
- asynchronous - Vala 中委托的异步作用域是什么?
- php - 使用ajax时如何在php页面上隐藏echo json_data?
- android - 带有 Xamrin Forms 的 Firebase 自定义声音通知适用于 IOS,但在应用未运行时不适用于 android
- django - django REST framework api 不使用模型
- c# - 根据条件连接字符串
- android-support-library - 有没有办法在旧项目中使用 androidX 库(如 Firebase Crashlytics)而不将项目迁移到 androidX?
- javascript - 如何正确设置/读取 js-cookie 库中的 cookie?