import pygame from pygame .locals import * import sys pygame.init() display = pygame.display.set_mode((300,300)) FPS_CLOCK = pygame.time.Clock() flag = 1 while 1: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: if flag == 1: pygame.mouse.set_visible(False) flag = 0 elif flag == 0: pygame.mouse.set_visible(True) flag = 1 pygame.display.update() FPS_CLOCK.tick(30)