如何在 Pygame 中获得显示器的分辨率? [英] How to get the resolution of a monitor in Pygame?
问题描述
我只是想知道是否有可能在 Pygame 中获得显示器的分辨率,然后使用这些尺寸创建一个窗口,以便启动程序检测显示器分辨率,然后自动使窗口适合屏幕全屏显示.
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.
我目前正在使用 pygame.display.set_mode((AN_INTEGER, AN_INTEGER))
创建窗口.我知道您可以使用 pygame.display.Info()
获取视频信息,包括显示器分辨率,但是我如何提取这些值,然后在 pygame.display.set_mode() 中使用它们
???
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()
???
提前致谢,伊尔蒙特
推荐答案
你可以使用pygame.display.Info()
:
文档 说:
current_h, current_w:当前视频模式的高度和宽度,或如果在调用 display.set_mode 之前调用桌面模式.
(current_h、current_w 从 SDL 1.2.10 开始可用,pygame1.8.0) 它们在错误时为 -1,或者如果正在使用旧的 SDL.1.8.0)
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()
创建一个具有 current_h
和 current_w
属性的信息对象.在调用 display.set_mode
之前创建信息对象,然后从 current_h
和 current_w
调用 display.set_mode
目的.
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.
示例:
infoObject = pygame.display.Info()
pygame.display.set_mode((infoObject.current_w, infoObject.current_h))
这篇关于如何在 Pygame 中获得显示器的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!