Python Forum

Full Version: set_focus() in python pywinauto
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to create a script that will cycle through 4 open windows. I am able to connect to the open windows fine. But I cannot figure out how to set_focus() on a window. I have read the documentation and googled, but cannot figure out what I am missing. I appreciate the advice.

My existing code is:
import pywinauto
 
apps = []
windows = pywinauto.Desktop(backend="uia").windows()

for w in windows:
    if 'Microsoft' in w.window_text():
        apps.append(pywinauto.Application().connect(handle=w.handle))

for x in apps:
    x.set_focus()
#I also tried:
    pywinauto.set_focus(x)