Posts: 4
Threads: 1
Joined: Apr 2022
When I attempt to run
isburger = pyautogui.locateOnScreen('singleburger.png', region=(str(xregion,yregion,)+str(length,height))) I keep getting the error
Error: line 88, in <module>
isburger = pyautogui.locateOnScreen('singleburger.png', region=(str(xregion,yregion,)+str(length,height)))
TypeError: decoding str is not supported
yregion, xregion, length, and height variables are all integers
However, when left as an integer, it returns
Error: TypeError: can only concatenate str (not "int") to str
Help greatly appreciated!
Posts: 1,583
Threads: 3
Joined: Mar 2020
Apr-17-2022, 03:56 AM
(This post was last modified: Apr-17-2022, 03:56 AM by bowlofred.)
region should be a tuple of 4 integers. So possibly you want
isburger = pyautogui.locateOnScreen('singleburger.png', region=(xregion, yregion, length, height))
Posts: 4
Threads: 1
Joined: Apr 2022
(Apr-17-2022, 03:56 AM)bowlofred Wrote: region should be a tuple of 4 integers. So possibly you want
isburger = pyautogui.locateOnScreen('singleburger.png', region=(xregion, yregion, length, height))
Ran that, got back
Error: TypeError: can only concatenate str (not "int") to str
Posts: 4
Threads: 1
Joined: Apr 2022
If it helps, here is the full script:
import pyautogui
import time
import PIL
regionx = 0
regiony = 0
length = 1920
height = 1080
pyautogui.alert("Please put you cursor over the single burger selection button within 5 seconds of pressing OK")
time.sleep(5)
bplain = pyautogui.position()
print("single burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the double burger selection button within 5 seconds of pressing OK")
time.sleep(5)
bdouble = pyautogui.position()
print("double burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the lettuce burger selection button within 5 seconds of pressing OK")
time.sleep(5)
blettuce = pyautogui.position()
print("lettuce burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the bloxy cola selection button within 5 seconds of pressing OK")
time.sleep(5)
cola = pyautogui.position()
print("cola button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the fries selection button within 5 seconds of pressing OK")
time.sleep(5)
fries = pyautogui.position()
print("fries button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Put your cursor over the upper left corner of a customer's speech bubble within 5 seconds of pressing OK. Do not let the cash register images get in the box.")
time.sleep(5)
topleft = pyautogui.position()
print("top left is captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Put your cursor over the bottom right corner of a customer's speech bubble within 5 seconds of pressing OK. Do not let the cash register images get in the box.")
time.sleep(5)
btmrght = pyautogui.position()
print("bottom right is captured")
selection = pyautogui.alert("Calibration is complete. Please finish the current customer's order (if there is one) before pressing OK.")
## Finding the region of selection:
topleftstr = str(topleft)
btmrghtstr = str(btmrght)
topleftList = topleftstr.split(sep=", y=", maxsplit = 2)
endregionList = btmrghtstr.split(sep=", y=",maxsplit = 2)
print(str(topleftList))
print(str(endregionList))
regionx,regiony = topleftList
endregionx,endregiony = endregionList
regionxfixed = regionx.split(sep="=",maxsplit=2)
endregionxfixed = endregionx.split(sep="=",maxsplit=2)
regionyfixed = regiony.split(sep=")",maxsplit=2)
endregionyfixed = endregiony.split(sep=")",maxsplit=2)
nox,xregion = regionxfixed
print(xregion)
nox2,endxregion = endregionxfixed
print(endxregion)
yregion,noy = regionyfixed
print(xregion)
endyregion,noy2 = endregionyfixed
print(endxregion)
length = int(endxregion) - int(xregion)
height = int(endyregion) - int(yregion)
time.sleep(3)
##while True:
if True:
isburger = pyautogui.locateOnScreen('singleburger.png', region=(xregion, yregion, length, height))
if isburger == "ImageNotFoundException":
isdburger = pyautogui.locateOnScreen('doubleburger.png', region=(str(xregion,yregion,)+str(length,height)))
if isdburger == "ImageNotFoundException":
pyautogui.leftClick(blettuce)
else:
pyautogui.leftClick(bdouble)
else:
print("found single burger")
pyautogui.leftClick(bplain)
isCola = pyautogui.locateOnScreen('cola.png', region=(str(xregion,yregion,)+str(length,height)))
if not isCola == "ImageNotFoundException":
print("found cola")
pyautogui.leftClick(cola)
isFries = pyautogui.locateOnScreen('fries.png', region=(str(xregion,yregion,)+str(length,height)))
if not isFries == "ImageNotFoundException":
print("found fries")
pyautogui.leftClick(x=599, y=537)
time.sleep(5) Line 86 and below is what is giving the error.
Posts: 1,583
Threads: 3
Joined: Mar 2020
You didn't make the change everywhere, and you didn't show the full traceback to see which line caused it. I'm presuming that line 86 is now working, but 88 or 96 is now generating the error.
Posts: 4
Threads: 1
Joined: Apr 2022
Apr-17-2022, 01:17 PM
(This post was last modified: Apr-17-2022, 01:17 PM by dude8074.)
(Apr-17-2022, 05:36 AM)bowlofred Wrote: You didn't make the change everywhere, and you didn't show the full traceback to see which line caused it. I'm presuming that line 86 is now working, but 88 or 96 is now generating the error.
86 is still producing the error:
Error: Traceback (most recent call last):
File "/Volumes/PortableSSD/untitled_folder/imagefinder.py", line 86, in <module>
isburger = pyautogui.locateOnScreen('singleburger.png', region=(xregion, yregion, length, height))
File "/Users/dude8074/Library/Python/3.8/lib/python/site-packages/pyautogui/__init__.py", line 175, in wrapper
return wrappedFunction(*args, **kwargs)
File "/Users/dude8074/Library/Python/3.8/lib/python/site-packages/pyautogui/__init__.py", line 213, in locateOnScreen
return pyscreeze.locateOnScreen(*args, **kwargs)
File "/Users/dude8074/Library/Python/3.8/lib/python/site-packages/pyscreeze/__init__.py", line 360, in locateOnScreen
retVal = locate(image, screenshotIm, **kwargs)
File "/Users/dude8074/Library/Python/3.8/lib/python/site-packages/pyscreeze/__init__.py", line 340, in locate
points = tuple(locateAll(needleImage, haystackImage, **kwargs))
File "/Users/dude8074/Library/Python/3.8/lib/python/site-packages/pyscreeze/__init__.py", line 259, in _locateAll_python
haystackImage = haystackImage.crop((region[0], region[1], region[0] + region[2], region[1] + region[3]))
TypeError: can only concatenate str (not "int") to str
with this script:
import pyautogui
import time
import PIL
regionx = 0
regiony = 0
length = 1920
height = 1080
pyautogui.alert("Please put you cursor over the single burger selection button within 5 seconds of pressing OK")
time.sleep(5)
bplain = pyautogui.position()
print("single burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the double burger selection button within 5 seconds of pressing OK")
time.sleep(5)
bdouble = pyautogui.position()
print("double burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the lettuce burger selection button within 5 seconds of pressing OK")
time.sleep(5)
blettuce = pyautogui.position()
print("lettuce burger button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the bloxy cola selection button within 5 seconds of pressing OK")
time.sleep(5)
cola = pyautogui.position()
print("cola button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Please put you cursor over the fries selection button within 5 seconds of pressing OK")
time.sleep(5)
fries = pyautogui.position()
print("fries button position captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Put your cursor over the upper left corner of a customer's speech bubble within 5 seconds of pressing OK. Do not let the cash register images get in the box.")
time.sleep(5)
topleft = pyautogui.position()
print("top left is captured")
pyautogui.alert("Position captured. Press OK to continue calibration. Do not move your character or adjust your camera zoom.")
pyautogui.alert("Put your cursor over the bottom right corner of a customer's speech bubble within 5 seconds of pressing OK. Do not let the cash register images get in the box.")
time.sleep(5)
btmrght = pyautogui.position()
print("bottom right is captured")
selection = pyautogui.alert("Calibration is complete. Please finish the current customer's order (if there is one) before pressing OK.")
## Finding the region of selection:
topleftstr = str(topleft)
btmrghtstr = str(btmrght)
topleftList = topleftstr.split(sep=", y=", maxsplit = 2)
endregionList = btmrghtstr.split(sep=", y=",maxsplit = 2)
print(str(topleftList))
print(str(endregionList))
regionx,regiony = topleftList
endregionx,endregiony = endregionList
regionxfixed = regionx.split(sep="=",maxsplit=2)
endregionxfixed = endregionx.split(sep="=",maxsplit=2)
regionyfixed = regiony.split(sep=")",maxsplit=2)
endregionyfixed = endregiony.split(sep=")",maxsplit=2)
nox,xregion = regionxfixed
print(xregion)
nox2,endxregion = endregionxfixed
print(endxregion)
yregion,noy = regionyfixed
print(xregion)
endyregion,noy2 = endregionyfixed
print(endxregion)
length = int(endxregion) - int(xregion)
height = int(endyregion) - int(yregion)
time.sleep(3)
##while True:
if True:
isburger = pyautogui.locateOnScreen('singleburger.png', region=(xregion, yregion, length, height))
if isburger == "ImageNotFoundException":
isdburger = pyautogui.locateOnScreen('doubleburger.png', region=(xregion, yregion, length, height))
if isdburger == "ImageNotFoundException":
pyautogui.leftClick(blettuce)
else:
pyautogui.leftClick(bdouble)
else:
print("found single burger")
pyautogui.leftClick(bplain)
isCola = pyautogui.locateOnScreen('cola.png', region=(xregion, yregion, length, height))
if not isCola == "ImageNotFoundException":
print("found cola")
pyautogui.leftClick(cola)
isFries = pyautogui.locateOnScreen('fries.png', region=(xregion, yregion, length, height))
if not isFries == "ImageNotFoundException":
print("found fries")
pyautogui.leftClick(x=599, y=537)
time.sleep(5) I'm thinking its probably an error with my math to calculate xregion , yregion , length , and height .
Posts: 1,583
Threads: 3
Joined: Mar 2020
On lines 5&6, you make regionx and regiony integers.
But on line 57 you throw that away and assign them from topleftList, which from line 51 we see are now strs
Then they're reassigned again on lines 66 and 72 (again to strs).
So by the time you get to 86, they're not ints. region has to be ints.
|