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

Mutant Bob picture Mutant Bob · Apr 15, 2016 · Viewed 31.9k times · Source

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)

Answer

Will picture Will · Apr 15, 2016

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()