Python 如何在Pygame中退出全屏模式?

Python 如何在Pygame中退出全屏模式?,python,pygame,toggle,fullscreen,exit,Python,Pygame,Toggle,Fullscreen,Exit,这可能是一个愚蠢的问题,但我找不到医生来解答这个问题,这是一个愚蠢的问题 Pygame为我提供了这些用于显示的标志。set.mode() 好的,我可以进入全屏模式。。下面是我的代码: __author__ = 'EricsonWillians' from pygame import * import ctypes init() user32 = ctypes.windll.user32 screenSize = user32.GetSystemMetrics(0)/2, user32.GetS

这可能是一个愚蠢的问题,但我找不到医生来解答这个问题,这是一个愚蠢的问题

Pygame为我提供了这些用于显示的标志。set.mode()

好的,我可以进入全屏模式。。下面是我的代码:

__author__ = 'EricsonWillians'

from pygame import *
import ctypes
init()
user32 = ctypes.windll.user32
screenSize = user32.GetSystemMetrics(0)/2, user32.GetSystemMetrics(1)/2

size = (screenSize)
screen = display.set_mode(size)
display.set_caption("Game")
done = False
clock = time.Clock()

def keyPressed(inputKey):
    keysPressed = key.get_pressed()
    if keysPressed[inputKey]:
        return True
    else:
        return False

while not done:
    for e in event.get():
        if e.type == QUIT:
            done = True
        if keyPressed(K_F10):
            if screen == display.set_mode(size):
                screen = display.set_mode(size, FULLSCREEN)
            else:
                screen = display.set_mode(size, "What flag should I put here for 'windowed'?")

    screen.fill((0,0,0))
    display.flip()
    clock.tick(60)

quit()
无法“切换回”全屏模式,因为SDL中没有“窗口化”标志

和“”不起作用。(至少,我不能让它工作)


我尝试过“-1”或“0”或“非全屏”,但都不起作用(以“0”为标志,屏幕会变得“怪异”。我不知道会发生什么,哈哈,但它没有窗口)。

只是不指定任何标志

if e.type is KEYDOWN and e.key == K_w:
    pygame.display.set_mode(size)
if e.type is KEYDOWN and e.key == K_f:
    pygame.display.set_mode(size, FULLSCREEN)
对我有用

编辑

要使用单键切换,请使用:

if (e.type is KEYDOWN and e.key == K_f):
    if screen.get_flags() & FULLSCREEN:
        pygame.display.set_mode(size)
    else:
        pygame.display.set_mode(size, FULLSCREEN)

你说得对!我以前试过,但用的是同一把钥匙。我和你一样,用另一把没有旗帜的钥匙,它成功了。我想知道为什么同一把钥匙不起作用。。。
if (e.type is KEYDOWN and e.key == K_f):
    if screen.get_flags() & FULLSCREEN:
        pygame.display.set_mode(size)
    else:
        pygame.display.set_mode(size, FULLSCREEN)