简体   繁体   English

在后台的特定程序/窗口上运行 python 脚本?

[英]running python script on a particular program/window in the background?

我使用 pydirectinput 制作了一个简单的宏(pyautogui 失败了,所以我不得不使用 pydirectinput )但是我无法在脚本运行时使用我的计算机我可以告诉 python 在特定窗口/程序上使用这个宏脚本吗?可以自由使用电脑,宏会在后台做它的东西吗?

If you want the script to run in the background with no window just rename the file extension to ".pyw"如果您希望脚本在没有窗口的情况下在后台运行,只需将文件扩展名重命名为“.pyw”

To stop a script that has no window, go into task manager -> details -> locate pythonw.exe -> End Task要停止没有窗口的脚本,请进入任务管理器 -> 详细信息 -> 找到 pythonw.exe -> 结束任务

Yes you can and it's very easy todo!是的,你可以,而且很容易做到!

Just Rename your script's file extension to .pyw只需将脚本的文件扩展名重命名为.pyw

.pyw files are used in Windows to indicate a script needs to be run using PYTHONW.EXE instead of PYTHON.EXE in order to prevent a DOS console from popping up to display the output. .pyw文件在 Windows 中用于指示需要使用PYTHONW.EXE而不是PYTHON.EXE运行脚本,以防止弹出 DOS 控制台以显示输出。 This patch makes it possible to import such scripts, in case they're also usable as modules.此补丁使导入此类脚本成为可能,以防它们也可用作模块。

In Order to close that run file you can just open your "Windows Task Manager" using the shortcut ctrl + shift + Esc and then find pythonw.exe and click on DELETE button or End Task Button in Bottom为了关闭该运行文件,您可以使用快捷键ctrl + shift + Esc打开“Windows 任务管理器”,然后找到pythonw.exe并单击底部的DELETE按钮或End Task按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM