So today i posted a question regarding pygame and i got the answer i had to use a function in pygame called pygame.font.Font.size() i went to the documentation of pygame and found this function but i did not understand what it meant by the documentation i guess i understood i should give a parameter as a string and it gives the height and width of my string if i am going to render it as a text I know i am not able to explain it clearly but i will try my best.
Here is some code to explain it:
import pygame
pygame.init()
width = 800
height = 600
a = [""]
win = pygame.display.set_mode((width, height))
font = pygame.font.Font("freesansbold.ttf", 32)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
for i in "hello how are you?":
a[0] = a[0] + i
text_1 = font.render(a[0], True, (255, 255, 255))
win.fill((0, 0, 0))
win.blit(text_1, (0, 0))
print(font.size(i))
pygame.display.update()
a[0] = ''
run = False
pygame.quit()
I am sorry if you are not able to understand. My question is : If you run this it runs for a second and goes away but if you look at the console you see some tuple values. According to me the first tuple's first value is that is if I render the letter h on my screen the width of the letter is the first tuples first element and the height of h is the first tuples second element. To the second it would be the same thing but just for the second tuple Apply the process for the question "hello how are you?". if you notice the width of some charecter's is different. But my question is why for all elememts the height is the same? The height of the letter h and the height of the letter e is not the same they why the console is giving me aways the same height?