Advertisement
furas

pyautogui - function to locate numbers in different regions

Mar 7th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #! python3
  2.  
  3. import sys
  4. import pyautogui
  5.  
  6. # --- functions ---
  7.  
  8. def find(region):
  9.    
  10.     found = dict()
  11.  
  12.     for digit in range(10):
  13.         positions = pyautogui.locateAllOnScreen('digits/{}.png'.format(digit), region=region, grayscale=True)
  14.  
  15.         for x, _, _, _ in positions:
  16.             found[x] = str(digit)
  17.  
  18.     cols = sorted(found)
  19.     value = ''.join(found[col] for col in cols)
  20.    
  21.     return value
  22.  
  23. # --- main ---
  24.  
  25. # locate Power
  26. power = find( (888, 920, 150, 40) )
  27. print(power)
  28.  
  29. # locate other value in different region
  30. other = find( (888, 1120, 150, 40) )
  31. print(other)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement