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)
How can I exit Fullscreen mode in Pygame?