如何使用 pywinauto 获取特定的系统托盘图标?

How to get specific system tray icon using pywinauto?

例如通知区域的 Slack 图标:

在 "show hidden" 图标选项的情况下,我们如何获得特定图标?

这对我有用,

如果您的应用程序图标在任务栏上可见

app = Application(backend="uia").connect(path="explorer.exe")
sys_tray = app.window(class_name="Shell_TrayWnd")
sys_tray.child_window(title=<your icon>).click()

以防隐藏托盘中的应用程序图标

app = Application(backend="uia").connect(path="explorer.exe")
st = app.window(class_name="Shell_TrayWnd")
t = st.child_window(title="Notification Chevron").wrapper_object()
t.click()

# Handle notify icon  overflow window

list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)

# Select required option from drop-down 

ddm = desk.create_window(best_match="DropDownMenu")
desk.wait_for_window_to_appear(ddm, wait_for='ready', timeout=20, retry_interval=2)
ddm.child_window(title=<select option>, control_type="MenuItem").click_input()

使用此代码(修改 sunil-kumar 代码)

from pywinauto import Application
import time

app = Application(backend="uia").connect(path="explorer.exe")
st = app.window(class_name="Shell_TrayWnd")
t = st.child_window(title="Notification Chevron").wrapper_object()
t.click()

time.sleep(0.25)

list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)

list_box_win.child_window(title="APPLICATION NAME").click()