python程序中的.pyw文件 [英] .pyw files in python program

查看:57
本文介绍了python程序中的.pyw文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 编程的新手.任何人都可以解释什么是 *.pyw 文件以及它是如何工作的.

I am new to Python programming. Can anybody provide an explanation on what a *.pyw file is and how it works.

推荐答案

Python 脚本(扩展名为 .py 的文件)将由python.exe 默认情况下.这个可执行文件打开一个终端,它保持即使程序使用 GUI 也能打开.如果你不想这样发生,使用扩展名 .pyw 这将导致脚本默认情况下由 pythonw.exe 执行(两个可执行文件都位于Python 安装目录的顶层).这抑制启动时的终端窗口.

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.

您还可以使用 pythonw.exe 执行所有 .py 脚本,设置这通过通常的设施,例如(可能需要管理权限):

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 的应用程序显然不需要或不需要控制台窗口.

So in practice the only difference is that one leaves a console window hanging around and the other doesn't. The most obvious usage for *.pyw are GUI apps since an app with an independent GUI obviously does not need or want the console window around.

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

There are some subtle implementation differences between python.exe and pythonw.exe see https://stackoverflow.com/a/30313091/3703989

这篇关于python程序中的.pyw文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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