title: How do I make a rectangle in pygame that automatically moves to my mouse location?
body: <p>I have been trying to make a rectangle that moves to my mouse location, but it doesn't seem to be working. Here is my code:</p>
  
  <pre><code>import random, pygame, sys, pickle, pygame.mouse, pygame.draw
  from pygame.locals import *
  pygame.mixer.init()
  #             R    G    B
  WHITE     = (255, 255, 255)
  BLACK     = (  0,   0,   0)
  RED       = (255,   0,   0)
  GREEN     = (  0, 255,   0)
  DARKGREEN = (  0, 155,   0)
  DARKGRAY  = ( 40,  40,  40)
  BGCOLOR = BLACK
  
  pygame.init()
  
  DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
  DISPLAYSURF.fill(BLACK)
  rectangle = pygame.draw.rect (DISPLAYSURF, DARKGREEN, Rect((100,100), (130,170)))
  pygame.display.update()
  
  while True:
      DISPLAYSURF.fill(BLACK)
      #print pygame.mouse.get_pos()
      rectangle.move(pygame.mouse.get_pos())
      pygame.display.update()
      for event in pygame.event.get():
              if event.type == QUIT:
                      pygame.mixer.music.stop()
                      pygame.quit()
                      sys.exit()
  </code></pre>
  
  <p>I try running the code, but I only see a green rectangle for a millisecond, and then it disappears.</p>