title: how can i stop the endless loop with pygame.time.set_timer
body: <p>Want to change the color of the screen more often. It should be some kind of blinking.
  This should happen when the button is pressed.
  But the program runs in an endless loop.</p>
  <pre><code>import pygame
  pygame.init()
   
  screen = pygame.display.set_mode((500, 500))
  timer = pygame.time.Clock()
  
  WHITE = (255, 255, 255)
  RED = (255, 0, 0)
  
  bg_active_color = WHITE
  screen.fill(WHITE) 
  CHANGE_COLOR = pygame.USEREVENT + 1
  
  pygame.time.set_timer(CHANGE_COLOR, 500)
  counter = 0  
  running = True
  while running:   
          for event in pygame.event.get():
              if event.type == pygame.KEYDOWN: 
                  if event.key == pygame.K_LEFT:                
                      if event.type == CHANGE_COLOR:
                          counter += 1                      
                          if counter &lt; 4:
                              if bg_active_color == RED:
                                  screen.fill(RED)
                                  bg_active_color = WHITE
                              elif bg_active_color == WHITE:
                                  screen.fill(WHITE)
                                  bg_active_color = RED 
                          else:
                              pygame.time.set_timer(CHANGE_COLOR,0)
                              print(&quot;end&quot;)
                      
              
                      if event.type == pygame.QUIT:        
                          running = False
       
          pygame.display.update()
  
          timer.tick(30)
    
  pygame.quit()
  </code></pre>