import pygame import sys import random
def generate_text(): word = "" for i in range(0,50): word += str(random.randint(0,9)) return word
FPS = 60 WIDTH = 800 HEIGHT = 600 WHITE = (255, 255, 255) pygame.init() pygame.font.init() font = pygame.font.SysFont('Arial', 36) RANDCOLOR = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) clock = pygame.time.Clock() sc = pygame.display.set_mode((WIDTH,HEIGHT)) x = 0 y = 0
sc.fill(WHITE) while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: RANDCOLOR = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) text_surface = font.render(generate_text(), True, RANDCOLOR) sc.blit(text_surface, (x, y)) y = y + 50 pygame.display.update() print(generate_text()) clock.tick(FPS)
|