是否可以使用标准库(无需额外的模块)来最小化python中的控制台? [英] Is it possible to minimize the console in python with the standard librairy (without extra module)?
问题描述
我编写了一个使用控制台的程序。大多数情况下,用户必须查看控制台信息。对于命令行中的特定功能,我想在不增加控制台的情况下运行脚本。我只是不想看到该窗口,但它可以在任务栏中。我知道我可以使用其他模块(gui,win32等)来执行此操作,但是我想使用标准的python librairy。
I wrote a program that uses the console. Most of the time, the user must see the console informations. For a specific function from command line, I would like to run the script without the console rises. I just don't want see the window but it can be in the task bar. I know I can use extra modules (gui, win32,..) to do that but I would like to use the standard python librairy.
有可能这样做吗?
该程序应在Windows上运行。 (python 2.7)
The program should run on Windows. (python 2.7)
我指定了...我知道我也可以使用pythonw.exe。然后的问题是,如何有时使用python.exe和pythonw.exe(从命令行)针对特定功能启动相同的脚本?
I specify... I know I can use pythonw.exe too. The question then is how to launch the same script with python.exe sometimes and with pythonw.exe (from command line) for a specific function?
推荐答案
通过Google找到了这个问题,因此要回答这个问题,如何在运行Python脚本时最小化(而不是完全隐藏)Windows上的控制台窗口:
Found this question via google, so to answer the question, how to minimize (not completely hide) the console window on Windows when running a Python script:
# Python 3
import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )
GetConsoleWindow()将返回当前控制台的窗口句柄。
ShowWindow(hWnd,nCmdShow)将设置特定窗口的属性。 6
是 SW_MINIMIZE
。单击链接以获取其他参数。
GetConsoleWindow() will return the window handle for the current console.
ShowWindow(hWnd, nCmdShow) will set the properties for the specific window. 6
is SW_MINIMIZE
. Click on the link for other parameters.
这篇关于是否可以使用标准库(无需额外的模块)来最小化python中的控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!