Getting the name of the active window
From daniweb
import win32gui
w=win32gui
w.GetWindowText (w.GetForegroundWindow())
How to remember currently active window and then make it focused when needed?
Well,In windows,you can use win32gui.GetForegroundWindow()
to save the hwnd
of window.(Use pywin32 module).
import win32gui
window_hwnd = win32gui.GetForegroundWindow() # this will return a number(the hwnd of active window when it is running)
To make it active:
win32gui.SetForegroundWindow(window_hwnd)
If you want to get the hwnd
of tkinter,you can use
int(root.frame(),16) # root is a Tk() or Toplevel()
Change the active Window
I think the object method you're after is activate
:
>>> help(win.activate)
Help on method activate in module
pygetwindow._pygetwindow_win:
activate() method of
pygetwindow._pygetwindow_win.Win32Window instance
Activate this window and make it the foreground window.
So changing your code as follows should work.
import pygetwindow as gw
win = gw.getWindowsWithTitle('Photoshop')[0]
win.activate()
Related Topics
Break // in X Axis of Matplotlib
How to Create Test and Train Samples from One Dataframe with Pandas
How to Convert Comma-Delimited String to List in Python
How to Manually Create a Legend
How to Get the Utc Time of "Midnight" for a Given Timezone
Emulating Bash 'Source' in Python
How to Limit Concurrency with Python Asyncio
Decode Escaped Characters in Url
How to Count the Occurrence of a Certain Item in an Ndarray
Most Recent Previous Business Day in Python
How to Debug in Django, the Good Way
How to Find All Positions of the Maximum Value in a List
Get the Second Largest Number in a List in Linear Time