Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@Maxime Lorant answer is what you want. Suppose you have a list with your names.</p> <pre><code>names = ["Name1", "Name2", "Name3"] f = open("names.txt", "a") for i in names: f.write(i + "\n") f.close() </code></pre> <p>If names.txt was a blank file, now the content of it should like:</p> <pre><code>Name1 Name2 Name3 </code></pre> <p><strong>EDIT</strong> <br/> <br/> Now I see what you are trying to achieve. Please see this link : <a href="http://sivasantosh.wordpress.com/2012/07/18/displaying-text-in-pygame/" rel="nofollow noreferrer">http://sivasantosh.wordpress.com/2012/07/18/displaying-text-in-pygame/</a></p> <p>Basically, the newline character won't work in pygame - you have to change the coordinates of your text rectangle. I am kinda new to pygame but I managed to do what you want and here's my naive approach (I edited code from the link above):</p> <pre><code>#... f = open("t.txt") lines = f.readlines() f.close() basicfont = pygame.font.SysFont(None, 48) text = basicfont.render('Hello World!', True, (255, 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)) for i in lines: # each i has a newline character, so by i[:-1] we will get rid of it text = basicfont.render(i[:-1], True, (255, 0, 0), (255, 255, 255)) # by changing the y coordinate each i from lines will appear just # below the previous i textrect.centery += 50 screen.blit(text, textrect) #... </code></pre> <p>Here's the result:<img src="https://i.stack.imgur.com/jn7Yy.png" alt=""></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload