如何使用Python聚焦或最小化窗口?

如何使用Python聚焦或最小化窗口?,第1张

如何使用Python聚焦或最小化窗口

您需要通过窗口枚举并匹配窗口标题才能获得所需的窗口。下面的代码搜索标题为“ firefox”的窗口并设置焦点:

import win32guitoplist = []winlist = []def enum_callback(hwnd, results):    winlist.append((hwnd, win32gui.GetWindowText(hwnd)))win32gui.EnumWindows(enum_callback, toplist)firefox = [(hwnd, title) for hwnd, title in winlist if 'firefox' in title.lower()]# just grab the first window that matchesfirefox = firefox[0]# use the window handle to set focuswin32gui.SetForegroundWindow(firefox[0])

为了最小化窗口,下面的行:

import win32conwin32gui.ShowWindow(firefox[0], win32con.SW_MINIMIZE)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5674405.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存