# How do I measure the bounds of a string in PyGame?

I am trying to position some text on my screen using pygame, and knowing the size of the string would help.

When using C# and XNA I could use SpriteFont.MeasureString("Hello World") to get the size of the rendered string.

Is there any way to do something similar in pygame?

You can use the size method

size()
size(text) -> (width, height)

Returns the dimensions needed to render the text. This can be used to help determine the positioning needed for text before it isrendered. It can also be used for wordwrapping and other layout effects.

Here is an example

myFont = pygame.font.Font(None, fontSize)

width  = myFont.size("Hello World")[0]
heigth = myFont.size("Hello World")[1]