python程序中的.pyw文件

2024-04-26 03:19:38 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
1条回答
网友
1楼 · 发布于 2024-04-26 03:19:38

Python scripts (files with the extension .py) will be executed by python.exe by default. This executable opens a terminal, which stays open even if the program uses a GUI. If you do not want this to happen, use the extension .pyw which will cause the script to be executed by pythonw.exe by default (both executables are located in the top-level of your Python installation directory). This suppresses the terminal window on startup.

You can also make all .py scripts execute with pythonw.exe, setting this through the usual facilities, for example (might require administrative rights):

https://docs.python.org/2/using/windows.html

因此,在实践中,唯一的区别是一个保留控制台窗口,另一个则不保留。对于*.pyw,最明显的用法是使用GUI应用程序,因为具有独立GUI的应用程序显然不需要或不需要控制台窗口。

python.exe和pythonw.exe之间存在一些细微的实现差异,请参见https://stackoverflow.com/a/30313091/3703989

相关问题 更多 >

    热门问题