如何在Pygame中获得监视器的分辨率?

我只是想知道我是否有可能在Pygame中获得显示器的分辨率,然后使用这些尺寸创建一个窗口,以便启动程序检测显示器分辨率,然后自动将窗口全屏显示在屏幕上.

我目前正在使用pygame.display.set_mode((AN_INTEGER,AN_INTEGER))来创建窗口.
我知道您可以使用pygame.display.Info()获取包括显示器分辨率在内的视频信息,但是如何提取这些值然后在pygame.display.set_mode()中使用它们?

提前致谢,
Ilmiont

解决方法:

你可以使用pygame.display.Info():

docs说:

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()创建一个Info对象,其属性为current_h和current_w.
在调用display.set_mode之前创建Info对象,然后使用对象中的current_h和current_w调用display.set_mode.

例:

infoObject = pygame.display.Info()
pygame.display.set_mode((infoObject.current_w, infoObject.current_h))
上一篇:如何在Android中获取ImageView / Bitmap的高度和宽度


下一篇:php – 按不是第一个维度的数值对多维数组进行排序