簡體   English   中英

pygame中的多行文字

[英]Multiple line text in pygame

剛剛在我的學校開了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)

只需在每個print或sys stdout流輸出后通過指定"\\n" (例如: print ("hello" + "\\n"開始新行,那么您的應用程序將寫入不同的行

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM