I am trying to have my PyGame window fullscreen, but I would like to have the buttons to close the program, and minimize the window. If this is possible in PyGame, please tell me how. Thank you in advance!
I am trying to have my PyGame window fullscreen, but I would like to have the buttons to close the program, and minimize the window. If this is possible in PyGame, please tell me how. Thank you in advance!
Yes. You can change the pygame.display.set_mode while running, and also you can use pygame.event to check quit.
Example code:
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()