import pygame from random import randint pygame.init() #create a game window clock = pygame.time.Clock() back = (255, 255, 255) #background color mw = pygame.display.set_mode((500, 500)) #main window mw.fill(back) #colors BLACK = (0, 0, 0) LIGHT_BLUE = (200, 200, 255) class TextArea(): def __init__(self, x=0, y=0, width=10, height=10, color=None): """ area: a rectangle in the right place and the right color """ #memorize the rectangle: self.rect = pygame.Rect(x, y, width, height) #fill color - either the passed parameter or the overall background color self.fill_color = color #place text def set_text(self, text, fsize=12, text_color=BLACK): self.text = text self.image = pygame.font.Font(None, fsize).render(text, True, text_color) #draw a rectangle with text def draw(self, shift_x=0, shift_y=0): pygame.draw.rect(mw, self.fill_color, self.rect) mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))