← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #255202]: How to use functions with a default region

 

Question #255202 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/255202

Description changed to:
Hi,

I'm trying to create a function where the caller can optionally pass a
region, if no region is passed the Screen region should be used as
default, but this is not working. What am I doing wrong?

This is my function:

def tryClick(img,reg=Screen, delay = 5):
    if reg.exists(img,delay):
        reg.click(reg.getLastMatch())
        return True
    else:
        print("tryClick failed for pattern" +str(img))
        return False

calling lines might be something like:

tryClick("img.png") #use Screen as region
tryClick("img2.png", myRegion) #use myRegion as region
tryClick("img3.png",myRegion2,60) #use myRegion2 and wait for one minute

I get an error like below when calling the function using the first line:
 File "C:\Users\ADMINI~1\AppData\Local\Temp\sikuli-tmp4130329311333098074.py", line 68, in tryClick
 if reg.exists(img,delay):
TypeError: exists(): self arg can't be coerced to org.sikuli.script.Region

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.