Python程序运行时,打开了多个窗口,使用win32gui模块可以设置指定的某一个窗口为当前活动窗口。
import re, timeimport webbrowserimport win32gui, win32con, win32com.client def _window_enum_callback(hwnd, wildcard): ''' Pass to win32gui.EnumWindows() to check all the opened windows 把想要置顶的窗口放到最前面,并最大化 ''' if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) is not None: win32gui.BringWindowToTop(hwnd) # 先发送一个alt事件,否则会报错导致后面的设置无效:pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available') shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys('%') # 设置为当前活动窗口 win32gui.SetForegroundWindow(hwnd) # 最大化窗口 win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) if __name__ == '__main__': webbrowser.open("https:///questions/14295337/win32gui-setactivewindow-error-the-specified-procedure-could-not-be-found以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。