【问题标题】:I cant run multiple user-defined functions that use PYAUTOGUI我无法运行多个使用 PYAUTOGUI 的用户定义函数
【发布时间】:2019-10-25 12:53:13
【问题描述】:

我目前在设置涉及 pyautogui 的用户定义函数时遇到问题。

我可以从其他 .py 文件导入函数,不用担心,但是当我尝试一个接一个地运行时,第二个实际上并没有控制鼠标和键盘。

下面的示例代码

def findProgram(point, taskbar_image):
    taskbar_image = r"file location"
    point = pyautogui.locateOnScreen(taskbar_image)
    point = pyautogui.center(point)
    pyautogui.moveTo(point, duration=.2)
    pyautogui.click()
    return

def findList(home, browser):
    home = (25, 35)
    browser = (45, 75)
    pyautogui.moveTo(home, duration=.2)
    pyautogui.click()
    pyautogui.moveTo(browser, duration=.2)
    pyautogui.click()
    return

findProgram(0, 0)

findList (0, 0)

当我运行它时(即使没有将它们导入另一个文件),第一个函数将起作用,但第二个函数不会。该过程完成,没有错误。我对编程很陌生,因此对任何缺乏清晰的地方表示歉意。

谢谢,

【问题讨论】:

    标签: python pyautogui


    【解决方案1】:

    我试过了

    def findProgram(point, taskbar_image):
        #taskbar_image = r"file location" #i don't have the image so i changed it with what it will give (pos)
        #point = pyautogui.locateOnScreen(taskbar_image)
        #point = pyautogui.center(point)
        point = (1,0)
        pyautogui.moveTo(point, duration=.2)
        pyautogui.click()
        return
    
    def findList(home, browser):
        home = (25, 35)
        browser = (45, 75)
        pyautogui.moveTo(home, duration=.2)
        pyautogui.click()
        pyautogui.moveTo(browser, duration=.2)
        pyautogui.click()
        return
    
    findProgram(0, 0)
    
    findList (0, 0)
    

    而且看起来没问题,所以问题可能出在你给出的图像上。

    两个提示: Findprogram() 似乎不需要任何参数,因为它在函数的第一行、第二行被覆盖,findlist() 也是如此

    【讨论】:

      猜你喜欢
      • 2014-06-06
      • 2019-08-27
      • 1970-01-01
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      相关资源
      最近更新 更多