Gen*_*sis 4 python windows console
如何在执行脚本时隐藏控制台?我想创建一个单独的函数来执行此操作(也许通过应用os/中的一些方法sys,我不知道),所以我不需要一些解决方案,例如将脚本扩展名从 更改.py为.pyw。
如果您想在执行期间隐藏窗口(并且您的脚本仅适用于 Windows),那么ctypes可能适合您。
使用这个答案,您可以接受输入然后隐藏它:
import ctypes
a = input('Input value here:')
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
SW_HIDE = 0
hWnd = kernel32.GetConsoleWindow()
user32.ShowWindow(hWnd, SW_HIDE)
# Do stuff here
Run Code Online (Sandbox Code Playgroud)
这是跑掉ShowWindow()C。您可以从 Windows 自己的文档中获取更多(深入)信息。