Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent python windows from being focused

I am running a Python script on windows 7 that opens a subprocess every few seconds. This subprocess opens a window and grabs focus, disrupting any attempt by the user to do normal work while the script is running. I do not have the ability to modify the subprocess code itself. Is there a way to designate all subprocesses opened by a python script as not-focused?

CLARIFICATION: I need the window to open and be viewable/selectable, just not immediately jump on top of everything else that is going on. In other words, it need to open in the background, not force itself into the foreground.

like image 251
Elliot Avatar asked May 26 '12 14:05

Elliot


1 Answers

Here is how I did this last

# Hide the cmd prompt window
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
p = subprocess.Popen(args, startupinfo=startupinfo)
like image 156
Nick Craig-Wood Avatar answered Oct 06 '22 07:10

Nick Craig-Wood