Encontre un codigo que habia hecho hace tiempo. Espero que te sirva
Código python:
Ver original#!/usr/bin/env python
#coding: UTF-8
import pygame
from string import letters
from string import whitespace
pygame.init()
size = width, height = 640, 480
#Colors
black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)
blue = (0, 0, 255)
red = (255, 0, 0)
class Text:
def __init__(self, FontName = None, FontSize = 20):
pygame.font.init()
self.font = pygame.font.Font(FontName, FontSize)
self.size = FontSize
def render(self, surface, text, color, position):
text = unicode(text, "UTF-8")
x, y = position
for i in text.split("\r"):
surface.blit(self.font.render(i, 1, color), (x, y))
y += self.size
screen = pygame.display.set_mode(size)
pygame.display.set_caption("UTF-8 con pygame")
text = Text("font.ttf", 30)
s = ""
pygame.key.set_repeat(100)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN:
if event.unicode in letters or event.unicode in whitespace:
s += str(event.unicode)
if event.key == pygame.K_BACKSPACE and len(s) > 0:
s = s[:-1]
if event.key == pygame.K_ESCAPE:
exit()
screen.fill(white)
text.render(screen, s, black, (0, 0))
pygame.display.flip()