Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the resolution of a monitor in Pygame?

Tags:

I'm just wondering if it is possible for me to get the resolution of a monitor in Pygame and then use these dimensions to create a window so that launching the program detects the monitor resolution and then automatically fits the window to the screen in fullscreen.

I am currently using pygame.display.set_mode((AN_INTEGER, AN_INTEGER)) to create the window. I am aware that you can get video info including the monitor resolution using pygame.display.Info() but how can I extract these values and then use them in pygame.display.set_mode()???

Thanks in advance, Ilmiont

like image 942
Ilmiont Avatar asked Nov 13 '13 12:11

Ilmiont


People also ask

What does the pygame display Set_mode () function do?

This function can be called before pygame. display. set_mode() to create the icon before the display mode is set. If the display has a window title, this function will change the name on the window.

How do you change display mode in pygame?

Setting the display mode is handled with the function pygame. display. set_mode((width, height), flags, depth) Initialize a window or screen for display. The only required argument in this function is a sequence containing the width and height of the new display mode.

Is it possible to get the screen size (resolution) with Pygame?

Pygame - Get screen size? It's a very short question: Is it possible to get the screen size (resolution) with pygame and how do i get it? Just an untested WAG ... There is also a pygame.display.Info () call you can print. Just an untested WAG ... There is also a pygame.display.Info () call you can print.

How to get height of an image in Pygame?

Create an image object using pygame.image.load (“Provide image path here “) and store it in a variable. To get height of the image use image.get_height () method, here image is the variable in which image object is stored.

How do I change the display mode in Pygame?

Setting the display mode is handled with the function pygame.display.set_mode ( (width, height), flags, depth) Initialize a window or screen for display . The only required argument in this function is a sequence containing the width and height of the new display mode.

How to make a game using pygame?

In python, game programming is done in pygame and it is one of the best modules for doing so. Import pygame. Initialize pygame. Form a screen by using pygame.display.set_mode () method. Get size of formed screen by using screen.get_size () method. Quit pygame. Attention geek!


1 Answers

You can use pygame.display.Info():

The docs say:

current_h, current_w: Height and width of the current video mode, or of the desktop mode if called before the display.set_mode is called.
(current_h, current_w are available since SDL 1.2.10, and pygame 1.8.0) They are -1 on error, or if an old SDL is being used.1.8.0)

pygame.display.Info() creates an Info Object with the attributes current_h and current_w. Create the Info Object before you call display.set_mode and then call display.set_mode with current_h and current_w from the object.

Example:

infoObject = pygame.display.Info() pygame.display.set_mode((infoObject.current_w, infoObject.current_h)) 
like image 101
Mailerdaimon Avatar answered Oct 26 '22 21:10

Mailerdaimon