程序使用PyAutoGui在Python Shell中工作,但不在命令提示符下工作

时间:2018-03-22 18:28:05

标签: python command-prompt pyautogui

所以我对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()

如果我尝试在Python Shell中运行它,它可以完美地运行,但是当我在命令提示符中运行它时,它只会崩溃,它会尝试查找图像(一些文字的图像,它定位在哪里。)

当它搜索Python shell中的图像时,它会搜索大约1秒并找到它并且一切正常但我甚至无法从命令提示符中获取错误消息,所以如果你能帮助我,我会很高兴的!

请原谅我的德语写作。 :d

0 个答案:

没有答案