python中myfont_Pygame.font.font.呈现类型E

你需要先创建你的字体myfont = pygame.font.SysFont(None,10) # use default system font, size 10

那你就可以了

^{pr2}$

最后,您将需要blitmytext到您的曲面并更新它以显示文本。在

编辑:如果这是完整的脚本,则需要在事件循环之前初始化显示:screen = pygame.display.set_mode((300,300)) # create a 300×300 display

然后,您可以在屏幕上快速播放文本:screen.blit(mytext, (0,0)) # put the text in top left corner of screen

pygame.display.flip() # update the display

由于文本是静态的,它也不需要在while True:循环中。你可以先显示文本。如果要根据事件更改文本,则应在循环中处理。在

编辑2

对于您在comments部分中的错误消息,问题是因为在您发出pygame.quit()命令之后,一些pygame命令仍然在运行。这是因为您的break命令只会中断for event…循环,但是您仍然在while True:循环中,因此blit命令仍然尝试运行。在

你可以这样做:import pygame

pygame.init()

screen = pygame.display.set_mode((1200,600))

myfont = pygame.font.SysFont(None, 30)

mytext = myfont.render(‘Hello world’, 1, (255, 100, 100))

running = True

while running:

for event in pygame.event.get():

if event.type==pygame.QUIT:

running=False

screen.fill((255, 255, 255))

screen.blit(mytext, (600, 300))

pygame.display.flip()

pygame.quit()

这应该可以工作,因为主循环依赖于running为真。单击quit将其设置为false,以便脚本干净地退出while循环,然后运行pygame.quit()命令。在

Original: https://blog.csdn.net/weixin_36401794/article/details/112894525
Author: 东奥会计在线
Title: python中myfont_Pygame.font.font.呈现类型E

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/782002/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球