最大化 Photoshop 窗口失败

问题描述 投票:0回答:1

在我的脚本中我有:

def maximize_photoshop_window():
    photoshop_window = pyautogui.getWindowsWithTitle("Adobe Photoshop")[0]
    photoshop_window.maximize()
    time.sleep(1)  # Give a little time for the window to maximize

    def activate_photoshop_window():
    # Activate the Photoshop window titled "Untitled-1"
    pyautogui.getWindowsWithTitle("Untitled-1")[0].activate()
    time.sleep(1)  # Give a little time for the window to activate` 

# It stops with an error at this point (in Pycharm)
if __name__ == "__main__":
    maximize_photoshop_window()

错误是:

Traceback (most recent call last):   File "C:\1_python\Photoshop draw
circle in untitled-1 with spacebar.py", line 54, in <module>
    maximize_photoshop_window()   File "C:\1_python\Photoshop draw circle in untitled-1 with spacebar.py", line 9, in
maximize_photoshop_window
    photoshop_window = pyautogui.getWindowsWithTitle("Adobe Photoshop")[0]
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ 
IndexError: list index out of range

Process finished with exit code 1

想知道这里发生了什么?

python pyautogui
1个回答
0
投票

getWindowsWithTitle
返回具有给定标题的所有窗口的列表。根据错误消息,在这种情况下,它返回一个空列表,这可能意味着“Adobe Photoshop”不是窗口的确切标题。

© www.soinside.com 2019 - 2024. All rights reserved.