【问题标题】:Displaying text with pygame [duplicate]用pygame显示文本[重复]
【发布时间】:2013-12-30 17:51:12
【问题描述】:
import pygame, sys
from pygame.locals import *

BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = ( 255, 0, 0)


pygame.init()
size = (700, 500)
screen = pygame.display.set_mode(size)


DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('P.Earth')
while 1: # main game loop
     for event in pygame.event.get():
        if event.type == QUIT:

            pygame.display.update()

import time

direction = ''

print('Welcome to Earth')
pygame.draw.circ(screen, RED, [55,500,10,5], 0)
time.sleep(1)
print('Earth was a very prosperous planet. Filled with life and culture.')
time.sleep(2)

这只是其中的一部分。它不会显示在 pygame 屏幕上。 (如果你想知道我最后使用pygame.quit())我只是想让它工作。如果你能让你的答案更简单,那就太好了,因为我还是个初学者。我将如何显示文本?任何帮助都可以。谢谢。

【问题讨论】:

    标签: python text pygame


    【解决方案1】:

    您正在寻找使用 pygame font 模块。

    这是一个渲染然后在屏幕上定位字体的示例。 ()

    import pygame.font
    
    font = pygame.font.Font(None, 36) # None can be a font file instead
    text = font.render("Welcome to Earth", 1, (0, 0, 0))
    # Determine the location that should be allocated for the text
    text_box = text.get_rect(centerx=DISPLAYSURF.get_width()/2)
    # Draw the text onto the background
    background.blit(text, text_box)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      相关资源
      最近更新 更多