Prevent focusing python windows

I am running a Python script on Windows 7 that opens a subprocess every few seconds. This subprocess opens a window and captures focus, disrupting any attempt by the user to perform normal work while the script is running. I have no way to modify the subprocess code itself. Is there a way to designate all subprocesses opened by a python script as unfocused?

CONFIRMATION: I need to open a window and be visible / selectable, just don’t immediately jump over everything else that happens. In other words, it should be open in the background, and not force itself in the foreground.

+6
source share
2 answers

This 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) 
+3
source

You can start processes with various flags with subprocess.call

This example runs a console application without a user interface:

 >>> import shlex, subprocess >>> subprocess.call("C:\Windows\some_console_app.exe", shell=True) 
+1
source

Source: https://habr.com/ru/post/916750/


All Articles