在python中获取监视器大小 [英] Getting monitor size in python

查看:146
本文介绍了在python中获取监视器大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python并想创建一个全屏窗口.我知道pygame.FULLSCREEN标志,但是当我使用该标志时,屏幕周围会出现黑色区域​​.有什么办法可以使用python获取监视器的大小,以便我可以将窗口设置为正确的大小?

I am using python and want to create a fullscreen window. I know about the pygame.FULLSCREEN flag but when I use that there's areas of black around the screen. Is there any way to get the monitor size using python so I can make the window the correct size?

推荐答案

文档pygame.display.Info为您提供一个VideoInfo对象,该对象除其他属性外还具有以下功能:

Per the docs, pygame.display.Info gives you a VideoInfo object that has, among other attributes:

current_wcurrent_h:宽度和 当前视频模式的高度,或 的 桌面模式(如果在调用display.set_mode之前调用的话).

current_w, current_h: Width and height of the current video mode, or of the desktop mode if called before the display.set_mode is called.

pygame.display.list_modes提供了可用的全屏分辨率列表,例如,文档中的注释:

pygame.display.list_modes gives you a list of the available fullscreen resolutions, e.g., per a comment in the docs:

>>> pygame.display.list_modes()
[(1920, 1080), (1768, 992), (1680, 1050), (1600, 1200), (1600, 1024), (1600, 900
), (1440, 900), (1400, 1050), (1360, 768), (1280, 1024), (1280, 960), (1280, 800
), (1280, 768), (1280, 720), (1152, 864), (1024, 768), (800, 600), (720, 576), (
720, 480), (640, 480)]

最大到最小.您应该使用pygame.display.set_mode尝试其中一些可能性,以查看哪种方法对您来说很合适.

largest to smallest. You should try some of these possibilities with pygame.display.set_mode to see which one looks good for you.

这篇关于在python中获取监视器大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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