PyAutoGui在pythonshell中工作而不是在命令Promp中工作的程序

2024-10-08 18:22:42 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我对PyAutoGui有问题!
我有这个代码:

import pyautogui
import time
import sys
import os
def run():
    time.sleep(3)
    pyautogui.moveRel(30, 30)

    pyautogui.click()
    time.sleep(0.1)
    pyautogui.click()

    pyautogui.hotkey('ctrl', 'c')

    pyautogui.moveTo(1903, 2)

    pyautogui.click()

    pyautogui.moveTo(906, 1060)

    pyautogui.click()
    pyautogui.click()

    intervalvariable = 0.025
    intervalvariablebetweenwords = 0.4
    print("Please enter the first word and press Strg and v:")
    FullText = input()
    buttonlocation = None
    while buttonlocation == None:
        buttonlocation = pyautogui.locateOnScreen("button.png")
    buttonx, buttony = pyautogui.center(buttonlocation)
    pyautogui.moveTo(buttonx, buttony)
    pyautogui.moveRel(-20, 20)
    pyautogui.click()
    words = FullText.split(" ")
    for i in range(0, len(words)):
        if i == len(words)-4:
            intervalvariable = 0.015
            intervalvariablebetweenwords = 0
        pyautogui.typewrite(words[i], interval=intervalvariable);
        pyautogui.typewrite(" ", interval=0);
        time.sleep(intervalvariablebetweenwords)
    os.system('cls')
    print("Do You want to go again? If so, type 'YES' if not type something     else!")
    Again = input()
    if Again == "YES":
        os.system('cls')
        run()
    else:
        os.system('cls')
       sys.exit("Ok!")

run()

如果我试图在pythonshell中运行它,它的功能非常完美,但是当我在命令提示符下运行它时,它只会在它试图查找图像的地方崩溃(它是一些文本的图像,它的方向是自己的)。在

当它在pythonshell中搜索图像时,它会搜索大约1秒并找到它,并且一切正常,但是我甚至无法从命令提示符处获得错误消息,因此如果您能帮助我,我将非常高兴!在

请原谅我用德语写作。:D


Tags: runimportiftimeossleepsystemcls

热门问题