I have a problem when going from fullscreen mode to a smaller screen in Pygame. The window appears on the top left and I can't see any exit button, nor can I drag it to the center. Here is the code I am using:
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)
I have tried to center the smaller window on the screen which usually works fine, but not in this case.
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)
Any ideas how to center the window after exiting fullscreen?
question from:
https://stackoverflow.com/questions/66058567/pygame-exiting-fullscreen-mode-sets-window-outside-screen 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…