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
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.
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.
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.
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.
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.
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!
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With