I have some code to wrap a rectangle around some text in pygame:
import pygame as pgfont = pg.font.SysFont("Comic Sans MS", 30)def wrapRect(obj, color='Black'): rect = obj.get_rect() pg.draw.rect(obj, color, rect.inflate(10,10), 2) return objplayButton = wrapRect(font.render('Play', True, 'Black'))screen.blit(playButton, (200, 170))I made wrapRect to wrap a rectangle around the object given as a parameter.
This code doesn't work because before the blit() function places the text at the desired coordinates, I'm assuming the play button's default coordinates were (0,0), so when I used the inflate() function, it made those coordinates negative. As a result, the surrounding rectangle did not show. How do I make it so that wrapRect takes into account the fact that I may want to reposition the object beyond (0,0)?