您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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

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

import win32gui

toplist = []
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 matches
firefox = firefox[0]
# use the window handle to set focus
win32gui.SetForegroundWindow(firefox[0])

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

import win32con
win32gui.ShowWindow(firefox[0], win32con.SW_MINIMIZE)
python 2022/1/1 18:38:38 有268人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶