Search code examples
pythonpython-3.xvideopygameresolution

Can pygame detect the video mode of the screen?


Can Python and Pygame detect the video mode/resolution my screen is

I'm making my program run in full screen at 1920x1080 and this will work fine as I have a 16:9 screen @ 1920x1080 however if I run the code on a 4:3 screen @ 1024x768 then it gives me this error messgae

pygame.error: No video mode large enough for 1920x1080

Can pygame detect the video mode/resolution of the screen?


Solution

  • If you need the actual size of the display, not the best resolution to use, you do:

    import pygame
    pygame.display.init()
    # Before calling *.set_mode()
    i = pygame.display.Info()
    width = i.current_w
    height = i.current_h
    print("The screen size is: (%ix%i)" %width, height))
    

    Then you can use width and height to pygame.display.set_mode()