title: python listing mouse click coordinates
body: <p>I would like to record and append to a list the x and y coordinates of limited number of mouse clicks (10 in this case (This will be a variable)). The script needs to record the clicks over the desktop, browsers or applications in general.</p>
  
  <p>I am basically trying to create a list of coordinates for a flexible simple macro section of a larger program for desktop automation (Very simple and repetitive work but the layout does change that is why re-recording the coordinates is key).</p>
  
  <p>I have searched through "Automate the boring stuff" and cant get pyautogui to record the positions (It does execute mouse positions perfectly but not the pre-recording list). Also this cannot be limited to a single frame as seems to be the case in pygame.</p>
  
  <p>Im a noob any advice would be appreciated. I have included an image of the error I receive. The list portion is not included yet I will add that later.</p>
  
  <pre><code>from pynput import mouse
  
  NumberOfMouseClicks = 0
  
  def on_click(x, y, button, pressed):
      print(x, y)
      pynput.mouse.Listener.stop
  
  while NumberOfMouseClicks &lt; 10 :
      NumberOfMouseClicks = NumberOfMouseClicks + 1
      with mouse.Listener(on_click=on_click) as listener:
          listener.join()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5nO80.png" rel="nofollow noreferrer">enter image description here</a></p>