Pygame renderizar texto

Ejemplos de código

10
0

python cómo escribir texto en pygame

import pygame
pygame.init()
window = pygame.display.set_mode((500, 500)) 

def set_text(string, coordx, coordy, fontSize): #Function to set text

    font = pygame.font.Font('freesansbold.ttf', fontSize) 
    #(0, 0, 0) is black, to make black text
    text = font.render(string, True, (0, 0, 0)) 
    textRect = text.get_rect()
    textRect.center = (coordx, coordy) 
    return (text, textRect)

window.fill((255, 255, 255)) #Fills the whole window with white
#Places "Text in Pygame!" with an x,y coord of 250, 250 and 60 font size
totalText = set_text("Text in Pygame!", 250, 250, 60)
window.blit(totalText[0], totalText[1])
pygame.display.update()
7
0

pygame renderizar texto

"""system font"""
font = pygame.font.SysFont("Segoe UI", 35)

"""font from .ttf file"""
font = pygame.font.Font("path/to/font.ttf", 35)

textsurface = font.render("text", False, color)  # "text", antialias, color
surface.blit(textsurface, (x, y))

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................