473,699 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to give focus to another application

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
1 10705
On Jun 25, 1:23*pm, "massimo s." <deviceran...@g mail.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 SetForegroundWi ndow
method. I usually use win32gui.EnumWi ndows() to loop through all the
open processes and then use both win32gui.ShowWi ndow() and
win32gui.SetFor egroundWindow() 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16595
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so that the application being brought foreward can take control. It has been my observation that when I set the window.onblur function, the window will gain focus and then immediately lose focus (blur) to the first field, button, or whatever that is...
9
3705
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea. Obviously, must return focus and select to the textarea if too many have been keyed. When the function is called with onblur, it works in IE but not in Safari or NN. The function is called but the focus() and select() methods fail.
1
1468
by: Bob | last post by:
There is an aspect of Windows design that I've always disagreed with, and that is its focus-switching behavior. I'll be typing something, and another application pops up a message box right in the middle of what I'm doing. Maybe I'll even hit enter for a line break and instead answer a yes/no dialogue that I didn't even get a chance to read. Or, perhaps I ctrl-click on a web link and go off to do something else while I wait for it to load....
4
6436
by: Tom | last post by:
Another question relating to focus: Is it possible to set the focus to another program's window and send it keystrokes, YET still keep my VB program in the foreground (i.e. showing on the screen)? For instance, I want to monitor another program's window and send keytstrokes to it, yet I want my VB.NET program to remain in the foreground, where I will show progress indicators. Is this even possible in .NET? I believe it was in VB6 (cause...
5
7869
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some part of my application already in focus on a system level to make this work. If for example I am entering text at the command line and call a force_focus on my root window the call will not return till I click on a window in my application. The...
7
11921
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click' and it steals the focus from the user's current application. How can I prevent the hidden WebBrowser from stealing focus? (And better yet can I even suppress that click?_
5
2941
by: GraffixNYC | last post by:
We have a model dialog box(well a bunch of them) and it seems that when you cancel one of the in our application it will activate and bring the focus to another open window (not in our application) anyone know why this is and how to correct it? it should set the focus to our application and not "activate" another window and make that window have the focus
3
4245
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm application that need to "silently" use another app (called MapInfo) within itself - the intention is to use this app (which is quite sophisticated mapping application) and add some other extra functionality to it. We have a dll so we can run the...
4
5404
by: =?ISO-8859-15?Q?Albe_V=B0?= | last post by:
In my Application, I need to make a certain graphical refresh, interrogating SqlServer, only if Application has focus (i.e. the title bar is blue). Interrogating .Focused property of various forms of the project is not the way (maybe, enumerting forms and checking if at least one of them has focus may work, but I don't think this to be the most beautiful solution). Any idea?
0
8689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8885
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.