Can pygame determine the video mode of the screen?

Can Python and Pygame detect video mode / resolution on my screen

I run my program in full screen with a resolution of 1920x1080, and this will work fine, since I have a 16: 9 @ 1920x1080 screen, however, if I run the code on a 4: 3 @ 1024x768 screen, then it will give me this messgae error

pygame.error: no video mode big enough for 1920x1080

Can pygame determine video mode / screen resolution?

+5
source share
3 answers

If you need the actual display size, and not the best resolution to use, follow these steps:

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 for pygame.display.set_mode ()

+2
source

Yes, it seems pygame can detect various settings on your display.

The first thing to watch is this link here , reading should give you a lot of information on how pygame can help you with display modes. The How to Solve section is likely to be most useful to you.

After reading, you should go to this link here . You will see in the fourth paragraph after the links:

If precise control by pixel format or resolution display is required, use the functions pygame.display.mode_ok (), pygame.display.list_modes () and pygame.display.Info () to request display information.

So it’s best to read how to use and play with them to see how information is returned and used.

+2
source

If you pass (0, 0) or nothing like the resolution pygame.display.set_mode , pygame will use the resolution of your monitor (if display.set_mode been called before, it will use the resolution of your current display). You can also call pygame.display.list_modes() and select one of the returned permissions.

By the way, on Windows you need to take care, because the pygame window can be stretched. This answer will help.

+2
source

Source: https://habr.com/ru/post/1274216/


All Articles