# 等待指定像素颜色
def wait_color(x, y, color_hex):
while True:
# 获取当前颜色
current = pyautogui.pixel(x, y)
# 转16进制
current_hex = '#%02x%02x%02x' % current
print(f"检测坐标({x},{y}) 当前颜色:{current_hex}")
# 颜色一致
if current_hex.lower() == color_hex.lower():
print("颜色正确,继续执行")
break
time.sleep(0.3)
函数
使用方式。
# 等待颜色变化
wait_color(393, 669, "#cccccc")
比如:
# 2点击搜索
pyautogui.click(815, 132)
# 3等待颜色变化
wait_color(393, 669, "#cccccc")