import sys, time sys.stdout.reconfigure(encoding='utf-8', errors='replace') from pywinauto import Application from pywinauto.mouse import click, double_click app = Application(backend='uia').connect(process=int(sys.argv[1]), timeout=10) win = app.top_window() tree = win.descendants(control_type='Tree')[0] def expand_children(item): try: item.expand(); time.sleep(0.4) except Exception: pass return list(item.children()) nodes = [] for root in tree.children(): nodes.extend(expand_children(root)) for name in ['TwinCATProject1', 'I/O', '设备', '设备 1 (EtherCAT)', '模块 3 (EK1100)']: nxt = None for n in nodes: try: if n.window_text() == name: nxt = n break except Exception: pass if nxt is None: print('missing:', name); sys.exit(1) nodes = expand_children(nxt) target = None for n in nodes: if n.window_text() == '模块 10 (EL6695)': target = n break if not target: print('EL6695 not found'); sys.exit(1) r = target.rectangle() double_click(coords=(int((r.left + r.right) / 2), int((r.top + r.bottom) / 2))) time.sleep(4) win.set_focus() tabs = [t.window_text() for t in win.descendants(control_type='TabItem')] print('tabs:', tabs)