无法使用 pywinctl 激活窗口

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

这是我的代码:

import pywinctl as mm

win = mm.getAllAppsWindowsTitles()

try:
    aa = mm.getWindowsWithTitle(win.get('brave'))[0]
    aa.activate()
    print('worked')
except Exception as e:
    print(e)

它应该使用胜利字典中的当前标题激活勇敢者,但我收到此错误:

{'gjs': ['@!0,0;BDHF'], 'nautilus': ['rec'], 'brave': ['Ask a public question - Stack Overflow - Brave'], 'code': ['focus.py - rec - Visual Studio Code']}
list index out of range
python
1个回答
0
投票

对于有同样问题的其他用户,使用 PyWinCtl 寻址窗口时的代码可能如下所示:

import pywinctl as pwc

windows = pwc.getWindowsWithTitle('brave', condition=pwc.Re.CONTAINS, flags=pwc.Re.IGNORECASE)
for win in windows:
    # You can filter for another condition of your choice since there can be several brave windows
    if additional_condition:
        win.activate()
© www.soinside.com 2019 - 2024. All rights reserved.