手残待拯救 发表于 2021-4-20 03:53:20

pygame库未初始化

错误日志
E:\pychf\Scripts\python.exe E:/pychf/测试代码/game.py
pygame 2.0.1 (SDL 2.0.14, Python 3.9.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
True
Traceback (most recent call last):
File "E:\pychf\测试代码\game.py", line 33, in <module>
    screen.blit(font1.render(str(each), True, (0, 255, 0)), (0, pt))
pygame.error: Library not initialized

代码段
import sys
import pygame

pygame.init()
print(pygame.get_init())

size = width,high = 500,500
screen = pygame.display .set_mode(size)
pygame.display.set_caption("测试")
bg = (0,0,0,)

ont1 = pygame.font.Font(None,35)
lh = font1.get_linesize()
pt = 0

screen.fill(bg)

while True:
    for each in pygame.event.get():
      if each.type == pygame.quit():
            sys.exit()

      screen.blit(font1.render(str(each), True, (0, 255, 0)), (0, pt))
      pt += lh

      if pt > height:
            pt = 0
            screen.fill(bg)

    pygame.display.flip()

求解决方案,

手残待拯救 发表于 2021-4-20 03:54:37

如果有其他错误请一并指出
页: [1]
查看完整版本: pygame库未初始化