매일 사용하는 모든 응용 프로그램에서 시작하고 로그인하는 시작 스크립트를 작성하고 있습니다. 이를 위해 PyAutoGui 모듈, Python 3 및 내 2 개의 모니터에서 내 창의 레이아웃을 관리하는 다른 응용 프로그램을 사용하고 있습니다.PyAutoGui 모듈이 2 차 실행시 PermissionError를 제공합니다.
def smv(username, hotkey):
# starting application
os.system("smv.exe")
# it autofocuses on the username field
pyautogui.typewrite(username)
# (passwords are the same)
pyautogui.typewrite("PASSWORD\n")
# move to the window header (where title, minimize, close, etc..)
pyautogui.moveTo(100, 10, duration=0)
# drag the window to the far right of the primary monitor (since pyautogui doesn't support multiple monitors)
pyautogui.dragTo(1910, 20, duration=1, button="left")
# press the hotkey that belongs to the window layout manager
pyautogui.hotkey("ctrl", "alt", hotkey)
smv("username", "num7")
smv("username2", "num1")
이상한 점은 첫 번째 smv()가 완벽하게 실행된다는 것입니다. 응용 프로그램이 시작되고, 로그인하고, 창을 이동하고 단축키로 위치/크기를 조정합니다. 두 번째 smv()가 실행될 때 문제가 발생합니다.
Traceback (most recent call last):
File "main.py", line 15, in <module>
smv("username2", "num1")
File "D:\files\PyCharm\startup\smv2.py", line 10, in start
pyautogui.dragTo(1919, 10, duration=1, button="left")
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\__init__.py", line 683, in dragTo
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\__init__.py", line 274, in mouseDown
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\_pyautogui_win.py", line 393, in _mouseDown
File "d:\PortableApps\Miniconda3\lib\site-packages\PyAutoGUI-0.9.33-py3.5.egg\pyautogui\_pyautogui_win.py", line 480, in _sendMouseEvent
PermissionError: [WinError 5] Access denied.
나는 그것이 두 번째 실행에서 충돌 이유를 알아 내려고 내 머리를 균열 해요 : 응용 프로그램과 충돌 한 다음에 로그인, 시작 창 헤더로 이동하지만. try 및 except 블록 (사용하지 않음)을 사용해 보았습니다. 응용 프로그램이 시작되는 순서 (num1 이전과 numb1)를 전환했으나 사용하지 않았습니다 (1 번째 실행, 2 번째 충돌).
나는 2 개의 파일로 분할하여 세 번째 "main.py"파일에서 실행하려고 시도했습니다. 효율이 좋지는 않습니다. 알아요.하지만 차이가 있는지 확인하고 싶었습니다. 당신은 그것을 짐작했습니다 : 그렇지 않습니다. PermissionError에서 여전히 충돌합니다.