I have created a Pygame application where I have about 25 rectangles. I want to display 25 different text values (which is a numerical value but typecasted in str
- I mention this because I believe we need string in the first argument) at the center of the rectangle. I have imported a csv file that contains data.
def draw_point(text, pos):
font = pygame.font.SysFont(None, 20)
img = font.render(text, True, (0,0,0))
window.blit(img, pos)
def loop_func():
count = 0
while count < total_length:
data = data_pass[count] # data_pass is an empty list
pygame.draw.rect(window, (255,255,255), (20, 20, width, height))
draw_point(data, (width // 2, height // 2))
According to the loop_func()
function, the variable 'data' should be updated with a new value in every loop, and it is updating because I checked with the print()
function. But when I pass the variable to the draw_point()
function, it seems the function does not display the desired value. This is my output:
It is actually 25 different rectangles with an almost similar background color. I followed everything from the Pygame tutorial, but I am getting a very ugly font, and among 25 rectangles, only 1 rectangle shows the text at its center.
How can I fix this?