【问题标题】:Multiple line text in pygamepygame中的多行文本
【发布时间】:2018-03-11 19:44:42
【问题描述】:

刚刚在我的学校开始了 Python 课程,我们的第一个作业要求我们写出多行文本。我仍然无法弄清楚如何使用我的代码来做到这一点,所以如果有人可以提供帮助,那就太好了。代码贴在下面。

import pygame, sys
from pygame.locals import *

pygame.init()

pygame.display.set_caption('font example')
size = [640, 480]
screen = pygame.display.set_mode(size)

clock = pygame.time.Clock()

myfont = pygame.font.SysFont(None, 48)
text = myfont.render('My Name', True, (0, 0, 0), (255, 255, 255))
textrect = text.get_rect()
textrect.centerx = screen.get_rect().centerx
textrect.centery = screen.get_rect().centery

screen.fill((255, 255, 255))
screen.blit(text, textrect)

pygame.display.update()

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

clock.tick(20)

【问题讨论】:

  • 嗨@Damon。您提供的代码有一个缩进错误(请参阅while True 循环下方的for 循环)。您能否更新它以使其正常运行?这可以加快您获得此问题的反馈。
  • 使用for 循环逐行传输并增加y坐标。

标签: python pygame


【解决方案1】:

您可以通过指定"\n"(例如:print ("hello" + "\n")在每次 print 或 sys stdout 流输出后开始新行 那么您的应用程序将写入不同的行

【讨论】:

  • 这个问题不是指控制台,而是如何在窗口中打印文本。您的解决方案不响应 OP。
猜你喜欢
  • 2017-06-20
  • 1970-01-01
  • 2013-06-15
  • 2019-02-11
  • 1970-01-01
相关资源
最近更新 更多