我正在尝试将PyGame
窗口全屏显示,但是我想使用按钮关闭程序并最小化窗口。如果在PyGame
中可行,请告诉我如何做。预先谢谢你!
答案 0 :(得分:1)
是的。您可以在运行时更改pygame.display.set_mode
,也可以使用pygame.event检查退出。
示例代码:
import pygame,sys
pygame.init()
screen = pygame.display.set_mode((1440,900),pygame.FULLSCREEN,32) #Fullscreen - my display is 1440 by 900
pygame.display.set_caption("Example")
cursor_x,cursor_y = 0,0
cmddown = False
fullscreen = True
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
#Toggle Fullscreen (press escape to exit/enter fullscreen)
if event.key == pygame.K_ESCAPE:
if fullscreen == True:
screen = pygame.display.set_mode((1440,900)) #exits fullscreen
pygame.display.set_caption("Example")
fullscreen = False
else:
screen = pygame.display.set_mode((1440,900),pygame.FULLSCREEN,32)
pygame.display.set_caption("Example")
fullscreen = True
#Check Command + Q
if event.key == pygame.K_LMETA:
cmddown = True
if event.key == pygame.K_q:
if cmddown == True:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYUP:
cmddown = False
screen.fill((0,0,0))
pygame.display.flip()