Reputation: 33
I'm trying to complete this game using python, I'm a beginner, can anyone explain why my code isn't working please?
This is some of the code:
box = (x_pad+1, y_pad+1, x_pad+731, y_pad+550)
im = ImageGrab.grab(bbox=box)
im.save('/Users/CENSORED/full_snap__.png')
colour = (58, 15, 8)
img = Image.open('/Users/CENSORED/full_snap__.png')
rgb_img = img.convert('RGB')
for x in range(rgb_img.size()[0]):
for y in range(rgb_img.size()[1]):
r, g, b = rgb_img.getpixel((x, y))
if (r,g,b) == colour:
print('found image at {x}, {y}')
pyautogui.click(x,y)
time.sleep(.1)
This is the error:
File "/Users/CENSORED/Documents/Testing/gamecrusher.py", line 32, in <module>
for x in range(rgb_img.size()[0]):
TypeError: 'tuple' object is not callable
Upvotes: 0
Views: 32
Reputation: 207678
The problem is that rgb_img.size
is a tuple, not a callable method, so you don't put parentheses after it. You want:
for x in range(rgb_img.size[0]):
Likewise for y
.
Upvotes: 1