如何在Pygame中获得显示器的分辨率? [英] How to get the resolution of a monitor in Pygame?

查看:560
本文介绍了如何在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之前调用的话).
(从SDL 1.2.10开始,current_h,current_w和pygame都可用 1.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_hcurrent_w的信息对象. 在调用display.set_mode之前创建信息对象,然后从对象中使用current_hcurrent_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆