Answer the question
In order to leave comments, you need to log in
How to bring a window to the front?
I need a concept of how to bring a window in Windows with a certain name to the fore.
A specific, working version was stupidly not found on the Internet, either the plugins are dead, or the commands simply do not work.
For example, I need to switch to a window whose name contains "notepad", what script is needed in order to bring this window to the foreground?
This does not work:
hwnd = win32gui.FindWindow(None,"notepad")
win32gui.ShowWindow(hwnd, win32con.SW_NORMAL)
win32gui.SetForegroundWindow(hwnd)
Answer the question
In order to leave comments, you need to log in
Working code. Another thing is if there is no window with the name "notepad".
You can iterate through all windows and find those that have "notepad"
def enum_handler(hwnd, ctx):
if win32gui.IsWindowVisible(hwnd):
if 'notepad' in win32gui.GetWindowText(hwnd):
win32gui.SetForegroundWindow(hwnd)
win32gui.EnumWindows(enum_handler, None)
I found these commands, but they open the file:
#Найти и запустить приложение (программу)
from pywinauto.application import Application
app = Application(backend="uia").start("notepad.exe")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question