1

Just started a Python course at my school, and our first assignment requires us to write out text on multiple lines. I still cannot figure out how to do so with my code so if anyone could help, that'd be great. Code posted below.

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
  • 11
  • 1
  • Hi @Damon. The code you provided has an indentation error (see the `for` loop that goes beneath the `while True` loop). Could you please update it so that it runs without errors? That can speed up the feedback you'll get for this question. – Daniel Ruiz Mar 11 '18 at 20:15
  • 1
    Possible duplicate of [Rendering text with multiple lines in pygame](https://stackoverflow.com/questions/42014195/rendering-text-with-multiple-lines-in-pygame) – eyllanesc Mar 11 '18 at 21:09
  • Use a `for` loop to blit one line after the other and increment the y-coordinate each time. – skrx Mar 11 '18 at 21:18

1 Answers1

-1

simply you can start new line after each print or sys stdout stream output by specify "\n" (ex: print ("hello" + "\n" then your application will write to diffrent lines

mahmoudadel
  • 157
  • 1
  • 2
  • 11
  • 1
    The question does not refer to the console, but to how the text is printed in the window. Your solution does not respond to the OP. – eyllanesc Mar 11 '18 at 21:02