这是一段自动识别钉钉直播并自动点击直播的代码,期望效果是等到直播通知(dingtalk live.png)出现后点击并进入
为什么我这行代码的8-11行不能定位图片位置而是直接点击鼠标当前位置
import tkinter as tk
import pyautogui as pya
import time
def click():
aim = pya.locateOnScreen('dingtalk live.png')
while True:
if pya.locateOnScreen('dingtalk live.png'):
pya.click(aim)
break
else:
print("下一次循环")
time.sleep(3)
window = tk.Tk()
window.title('自动打开钉钉直播')
window.geometry('500x500')
head = tk.Label(window, text='自动打开', bg='pink', font=('微软雅黑', 14), width=36, height=3)
head.pack()
writer = tk.Label(window, text='coded by 陈欣然', bg='white', font=('微软雅黑',6), width=12,height=4)
writer.pack()
start = tk.Button(window, text='开始执行', width=18, height=1, command=click)
start.pack()
tk.mainloop()
需要看下后端的输出是什么
从而判断第11行是否生效
或者
修改成这样的试下:
import tkinter as tk
import pyautogui as pya
import time
def click():
x, y = pya.locateCenterOnScreen('dingtalk live.png')
while True:
if pya.locateCenterOnScreen('dingtalk live.png'):
print("坐标为", x, y)
pya.click(x, y)
break
else:
print("下一次循环")
time.sleep(3)
window = tk.Tk()
window.title('自动打开钉钉直播')
window.geometry('500x500')
head = tk.Label(window, text='自动打开', bg='pink', font=('微软雅黑', 14), width=36, height=3)
head.pack()
writer = tk.Label(window, text='coded by 陈欣然', bg='white', font=('微软雅黑', 6), width=12, height=4)
writer.pack()
start = tk.Button(window, text='开始执行', width=18, height=1, command=click)
start.pack()
tk.mainloop()
如果还没达到你的需求,看下输出的坐标值是多少
如有问题及时沟通
没看代码,假设你分辨率和图形确实一致,那么主要问题。onscreem的操作需要较长的时间,需要加time.sleep