import pygame pygame.init() font = pygame.font.Font(None, 30) def debug(info, y=15, x=15): Display_surf = pygame.display.get_surface() debug_surf = font.render(str(info), True, 'White') debug_rect = debug_surf.get_rect(topleft=(x, y)) # Clear the area where debug text will be drawn pygame.draw.rect(Display_surf, 'Black', (x, y, debug_rect.width, debug_rect.height)) Display_surf.blit(debug_surf, debug_rect)