Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the size (width x height) of my pygame window

Tags:

I have created a window using

pygame.display.set_mode((width, height), 
                        pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE)

Later on in the app I want to be able to ask that window its width and height so I can decide how to process the mouse position.

How do I access the dimensions of that pygame window elsewhere in the program? (event processing loop)

like image 769
Mutant Bob Avatar asked Apr 15 '16 17:04

Mutant Bob


1 Answers

You want to get the surface, then get the size from the surface object.

Using tuple unpacking:

w, h = pygame.display.get_surface().get_size()

like image 83
Will Avatar answered Sep 20 '22 17:09

Will