在 Pygame 中从全屏模式切换到小屏幕时遇到问题。窗口出现在左上角,我看不到任何退出按钮,也无法将其拖到中心。这是我正在使用的代码:
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
run = True
while run:
for event in pygame.event.get():
if event == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
# Exit fullscreen with escape key
if event.key == pygame.K_ESCAPE:
if screen.get_flags() & FULLSCREEN:
pygame.display.set_mode((400, 400))
else:
pygame.display.set_mode((0, 0), FULLSCREEN)
我曾尝试将较小的窗口居中放置在屏幕上,这通常可以正常工作,但在这种情况下不行。
import os
# .........
if screen.get_flags() & FULLSCREEN:
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.display.set_mode((400, 400))
else:
pygame.display.set_mode((0, 0), FULLSCREEN)
退出全屏后如何将窗口居中?
答案 0 :(得分:2)
这是pygame中的一个错误。
如果您需要这种行为,在 github 上报告问题的人找到了解决方法 (https://github.com/pygame/pygame/issues/2360)
希望它会在 2.0.2 中修复,我已经写了一个补丁来修复它 (https://github.com/pygame/pygame/pull/2460)