V
V
Vitaliy21122021-08-30 01:29:24
Python
Vitaliy2112, 2021-08-30 01:29:24

Wrote a code with a loop and operators, but gives a syntax error?

Here is the code:

import pyautogui 
import time

time.sleep(5)

while True:
  if cords = pyautogui.locateCenterOnScreen('join_button.png')
  
  else: 
    pyautogui.Click(cords)


Here is the error:
612c0982adda9860686052.png

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
ezbooz, 2021-08-30
@ezbooz

cords = pyautogui.locateCenterOnScreen('1.png') # если объект виден, то получаем координаты x,y
if cords: # если видно, то...
    print('найдено')
else: # иначе...
    print('не найдено')

Also can be used (based on your code):
if not cord: #если нет объекта на экране
    pyautogui.click(cords)

D
Developer, 2021-08-30
@samodum

You mixed up the assignment operator and the equality check

S
Stefan, 2021-08-30
@MEDIOFF

It even shows you with an arrow where the error is, is it really so difficult to look at the error and correct it and not go to the forum (== for comparison, = for assignment)

D
Daniil Shevkunov, 2021-08-30
@danila763

Or like this:

while True:
    if not cords := pyautogui.locateCenterOnScreen('1.png'):
        pyautogui.Click(cords)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question