How to blit text on a window with Pygame

import pygame



class Color:
	green = (0, 255, 0)


class Font:
	''' definition of type of fonts '''
	pygame.font.init()
	little = pygame.font.SysFont("Arial", 48)
	big = pygame.font.SysFont("Arial", 192)


class Text:
	''' definition of text with rendering method '''
	def text_render(font, text, color):
		return font.render(text, 1, color)

	def show_text():
		screen.blit(Text.hello, (0, 0))
		screen.blit(Text.World, (0, 200))
	hello = text_render(Font.big, "Hello", Color.green)
	World = text_render(Font.little, "World", Color.green)


def monitor_size():
	''' return width and height of the monitor screen '''
	info = pygame.display.Info()
	return info.current_w, info.current_h

def mainloop():
	''' main loop to show stuff on the screen '''
	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
		Text.show_text()
		clock.tick(60)
		pygame.display.update()


pygame.init()
w, h = monitor_size()
screen = pygame.display.set_mode((w - 100, h - 100), pygame.RESIZABLE)
clock = pygame.time.Clock()
mainloop()
The output in a resizable window (the text remains of the same size)

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.