python library pygame: centering text -


i have code:

# draw text font = pygame.font.font(none, 25) text = font.render("you win!", true, black) screen.blit(text, [screen_width / 2, screen_height / 2]) 

how can text width , height methods in java, can center text like:

screen.blit(text, [screen_width / 2 - text_w / 2, screen_height / 2 - text_h / 2]) 

if not possible, way ? i've found this example, didn't understand it.

you can dimensions of rendered text image using text.get_rect(), returns rect object width , height attributes, among others (see linked documentation full list). i.e. can text.get_rect().width.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -