while

EnderToy

Новичок
Пользователь
Ноя 2, 2020
1
0
1
Как сделать повторный запуск сценария после if? Я тупой

while True: # making a loop
try: # used try so that if user pressed other than the given key error will not be shown
if keyboard.is_pressed('q'): # if key 'q' is pressed
x1, y1 = win32api.GetCursorPos()
print(x1)
print(y1)
winsound.Beep(frequency, duration)
time.sleep(2)
x2, y2 = win32api.GetCursorPos()
winsound.Beep(frequency, duration)
print(x2)
print(y2)
x3 = x2 - x1
y3 = y2 - y1

image = pyautogui.screenshot(region=(x1, y1, x3, y3))
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
# cv2.imshow('Screenshot', imutils.resize(image))
# cv2.waitKey(0)
cv2.imwrite('5.png', image)

img = cv2.imread('5.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

config = r'--oem 3 --psm 6'

img = pytesseract.image_to_string(img)
import re

img = re.sub("-\n", '', img)
img = re.sub("\n", ' ', img)
img = img.lower()
print(img)
break # finishing the loop
else:
pass
except:
break
 

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 625
469
83
не писать break
 

Форум IT Специалистов