Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

python - Pygame exiting fullscreen mode sets window outside screen

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a bug in pygame.

If you need this behavior, someone who reported the issue on github found a workaround (https://github.com/pygame/pygame/issues/2360)

Hopefully it'll be fixed in 2.0.2, I've written a patch to fix it (https://github.com/pygame/pygame/pull/2460)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...