这是我的代码:
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
对于有同样问题的其他用户,使用 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()