pythonpygame

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


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)


Solution

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