By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,760 Members | 1,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,760 IT Pros & Developers. It's quick & easy.

how to give focus to another application

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Jun 25, 1:23*pm, "massimo s." <deviceran...@gmail.comwrote:
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.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.