how to give focus to another application

M

massimo s.

Hi,

I would like to know if 1)there is a Python way to tell under which
terminal process a Python command-line application is running 2)there
is a Python way to tell the OS to give focus to another window.

Solutions for Windows, Linux and OS X are welcome, even if OS-specific
(of course general solutions are better, but I can kludge & check the
platform).

Thanks,
M.
 
M

Mike Driscoll

Hi,

I would like to know if 1)there is a Python way to tell under which
terminal process a Python command-line application is running 2)there
is a Python way to tell the OS to give focus to another window.

Solutions for Windows, Linux and OS X are welcome, even if OS-specific
(of course general solutions are better, but I can kludge & check the
platform).

Thanks,
M.

On Windows, you can use the pywin32 modules to assist you. There's a
sub-module in them called win32gui that has a SetForegroundWindow
method. I usually use win32gui.EnumWindows() to loop through all the
open processes and then use both win32gui.ShowWindow() and
win32gui.SetForegroundWindow() to make the window I want appear.

I'm guessing that each OS has their own methods for this as you would
almost certainly have to use some kind of low-level calls to get
handles on processes you didn't create. Thus, the likelihood that
there are cross-platform methods is pretty low.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top