【发布时间】:2018-08-21 06:49:56
【问题描述】:
到目前为止,我对 Python 还是比较陌生,学习很有趣。
我想做的是使用 Python 及其库 Pyautogui 找到按钮的位置。
这是我的代码。
import webbrowser, pyautogui, time, datetime
class workDoneClicker:
def buttonTrack(self):
global x, y
x = ()
y = ()
while x == ():
coordinate = pyautogui.locateOnScreen('image.png')
x, y = (coordinate[0], coordinate[1])
return x, y
def clicker(self):
if pyautogui.alert(text="hi", title="hi") == 'OK':
webbrowser.open('http://example.com')
time.sleep(3)
self.buttonTrack()
self.clickButton()
print("executed")
else:
print("not executed")
我要做的是执行buttonTrack函数,直到找到值,然后返回x,y。
并在 clicker 函数中运行下一个代码。
使用 buttonTrack 函数获取值需要几秒钟,因为它必须加载网页。
但是当我运行代码点击器时,它似乎在找到值之前不会执行无限循环,而是运行下一个代码,因为我得到 'NoneType' object is not subscriptable。
请问如何按预期运行?和解释?
【问题讨论】:
-
你想为你的
x找到某个值或任何值吗?
标签: python loops infinite pyautogui