Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting monitor size in python

I am using python and want to create a fullscreen window. I know about the pygame.FULLSCREEN flag but when I use that there's areas of black around the screen. Is there any way to get the monitor size using python so I can make the window the correct size?

like image 394
None Avatar asked Apr 18 '10 15:04

None


People also ask

How can I tell my display size?

The size of a desktop computer monitor is determined by physically measuring the screen. Using a measuring tape, start at the top-left corner and pull it diagonally to the bottom-right corner. Be sure to only measure the screen; do not include the bezel (the plastic edge) around the screen.

How do I find my screen size in Pyautogui?

The pyautogui. size() function returns (1920, 1080) on a computer with a 1920×1080 resolution; depending on your screen's resolution, your return value may be different. The Size object returned by size() is a named tuple.


1 Answers

Per the docs, pygame.display.Info gives you a VideoInfo object that has, among other attributes:

current_w, current_h: Width and height of the current video mode, or of the desktop mode if called before the display.set_mode is called.

pygame.display.list_modes gives you a list of the available fullscreen resolutions, e.g., per a comment in the docs:

>>> pygame.display.list_modes()
[(1920, 1080), (1768, 992), (1680, 1050), (1600, 1200), (1600, 1024), (1600, 900
), (1440, 900), (1400, 1050), (1360, 768), (1280, 1024), (1280, 960), (1280, 800
), (1280, 768), (1280, 720), (1152, 864), (1024, 768), (800, 600), (720, 576), (
720, 480), (640, 480)]

largest to smallest. You should try some of these possibilities with pygame.display.set_mode to see which one looks good for you.

like image 169
Alex Martelli Avatar answered Sep 20 '22 12:09

Alex Martelli