Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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)

Solution 2:

You can run processes with a variety of flags with subprocess.call

This sample executes the console app with no UI whatsoever:

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

Post a Comment for "Prevent Python Windows From Being Focused"