2024-03-29 05:25:29 发布
网友
Python和Pygame能检测到我的屏幕的视频模式/分辨率吗
我让我的程序在1920x1080全屏运行,这会很好,因为我有一个16:9的屏幕@1920x1080,但是如果我在4:3屏幕上运行代码@1024x768,那么它会给我这个错误消息
pygame.error: No video mode large enough for 1920x1080
pygame能检测到屏幕的视频模式/分辨率吗?在
如果需要显示的实际大小,而不是使用的最佳分辨率,请执行以下操作:
import pygame pygame.display.init() # Before calling *.set_mode() i = pygame.display.Info() width = i.current_w height = i.current_h print("The screen size is: (%ix%i)" %width, height))
然后可以使用宽度和高度pygame.display.set_模式()
如果您将(0, 0)或什么都不传递给^{},pygame将使用监视器的分辨率(如果之前调用了display.set_mode,它将使用当前显示的分辨率)。您也可以调用pygame.display.list_modes()并选择返回的解析之一。在
(0, 0)
display.set_mode
pygame.display.list_modes()
顺便说一句,在Windows中你需要小心,因为pygame窗口可能会被拉长。This answer会有帮助的。在
是的,pygame似乎可以检测到显示器中的各种设置。在
首先要看的是this link here,阅读它会给你很多关于pygame如何帮助你使用显示模式的信息。“如何决定”部分可能对您最有用。在
读了之后,你会发现自己正在进入this link here。您将在链接后的第四段中看到:
If precise control is needed over the pixel format or display resolutions, use the functions pygame.display.mode_ok(), pygame.display.list_modes(), and pygame.display.Info() to query information about the display.
因此,最好仔细阅读如何使用它们,并与它们一起玩,看看这些信息是如何返回和使用的。在
如果需要显示的实际大小,而不是使用的最佳分辨率,请执行以下操作:
然后可以使用宽度和高度pygame.display.set_模式()
如果您将} ,pygame将使用监视器的分辨率(如果之前调用了
(0, 0)
或什么都不传递给^{display.set_mode
,它将使用当前显示的分辨率)。您也可以调用pygame.display.list_modes()
并选择返回的解析之一。在顺便说一句,在Windows中你需要小心,因为pygame窗口可能会被拉长。This answer会有帮助的。在
是的,pygame似乎可以检测到显示器中的各种设置。在
首先要看的是this link here,阅读它会给你很多关于pygame如何帮助你使用显示模式的信息。“如何决定”部分可能对您最有用。在
读了之后,你会发现自己正在进入this link here。您将在链接后的第四段中看到:
因此,最好仔细阅读如何使用它们,并与它们一起玩,看看这些信息是如何返回和使用的。在
相关问题 更多 >
编程相关推荐