英文:
Get the screen resolution in Pygame
问题
我有一个pygame程序,我想要它全屏显示,可以使用以下代码:
pygame.display.set_mode((width, height), pygame.FULLSCREEN)
我不知道计算机的宽度和高度(分辨率),所以我想要能够在macOS和Windows上获取它,可以使用类似以下的代码:
import platform
pf = platform.platform().lower()
if pf.startswith("windows"):
# 在这里添加代码
else:
# 在这里添加代码
我尝试了这个:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480), pygame.FULLSCREEN)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
英文:
I have a pygame program, and I want it to be fullscreen using
pygame.display.set_mode((width, height), pygame.FULLSCREEN)
.
I do not know the width and height (resolution) of the computer, so I want to be able to retrieve it on both macOS and Windows, using something like this for example:
import platform
pf = platform.platform().lower()
if pf.startswith("windows"):
# code here
else:
# code here
I tried this:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480), pygame.FULLSCREEN)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
答案1
得分: 2
set_mode
可以接受宽度和高度都为零以强制使用本机分辨率。所以你可以这样做:
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
要了解更多信息,请查看这里的文档:http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode。
英文:
The set_mode
can take a width and height of zero to force native resolution. So you can just do:
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
Take a look at the docs here for more information: http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论