防止python窗口被聚焦 [英] Prevent python windows from being focused

查看:135
本文介绍了防止python窗口被聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 7上运行Python脚本,该脚本每隔几秒钟打开一个子进程.该子进程打开一个窗口并获取焦点,从而破坏了用户在脚本运行时进行正常工作的任何尝试.我没有能力修改子流程代码本身.有没有一种方法可以将由python脚本打开的所有子进程都指定为非焦点?

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.

推荐答案

这是我最后一次这样做的方式

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)

这篇关于防止python窗口被聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆