title: Trying to update PIL.ImageGrab but it isnt working
body: <p>I am trying to make a code that will call for a button to be pressed.</p>
  
  <p>A function will tell which button is to be pressed. It will check if the button is a valid one (1 to 4), then will find the navigator control (custom from the app I am trying to automate, I can't find an option to order it to execute a specific), check its color according to the PIL in the memory and, if valid, press the button and wait until the button changes color to resume the code.</p>
  
  <pre><code>from pywinauto import application
  import pywinauto
  import PIL
  import time
  from array import *
  time.clock()
  
  def sanity_check():
      if 'app' not in globals():
          global app
          app = application.Application()
          app.connect(title="Contas a pagar")
      if 'screen' not in globals():
          global screen
          screen = PIL.ImageGrab.grab()
      if 'colorsarr' not in globals():
          global colorsarr
          colorsarr = [[(36, 210, 71),(82, 94, 105)],[(198, 62, 62),(84, 96, 107)],[(174, 218, 201),(169, 187, 207)],[(229, 13, 0),(64, 73, 81)]]
  
  def update_screen():
      screen = PIL.ImageGrab.grab()
  
  def click_button(number=1):
      if 1 &lt;= number &lt;= 4:
          number = int(number)
          buttonCoord = int((app.Contas_a_pagar.TBDBNavigator2.rectangle().right - app.Contas_a_pagar.TBDBNavigator2.rectangle().left)/4/2), int((app.Contas_a_pagar.TBDBNavigator2.rectangle().bottom - app.Contas_a_pagar.TBDBNavigator2.rectangle().top)/2)
          buttonCoord = app.Contas_a_pagar.TBDBNavigator2.rectangle().left + buttonCoord[0]*(number*2-1),buttonCoord[1]+app.Contas_a_pagar.TBDBNavigator2.rectangle().top
          if screen.getpixel(buttonCoord) == colorsarr[number-1][0]:
              pywinauto.mouse.click(button='left', coords=(buttonCoord))
              while screen.getpixel(buttonCoord) != colorsarr[number-1][1]:
                  update_screen()
                  continue
              return
          elif screen.getpixel(buttonCoord) == colorsarr[number-1][1]:
              print("Button unavailable")
              return
          else:
              print("Color check button " + str(number))
              return
  
  def automate_things():
      sanity_check()
      print(time.clock())
      for i in range(-3,10):
          click_button(i)
      print(time.clock())
  
  automate_things()
  </code></pre>
  
  <p>My problem is that my function <code>update_screen</code> should change what is stored in the var <code>screen</code> but it isn't, making the while loop infinite. Even if I put a window on the position it grabs the pixel color, it keeps getting the other color.</p>
  
  <p>The <code>colorsarr</code> array has on the 0-index the "pressable" color and in the 1-index the "unpressable" color</p>
  
  <p>This is my first python code, so probably I am doing something wrong. When complete, I will try code review for better code. While suggestions for better coding are welcome, the focus is just why the screen var isn't updating.</p>