当我的 python 脚本运行时,如何从桌面上删除这个黑色的命令提示符屏幕?
我使用 python 2 exe 将 service.py 脚本制作成 exe。一切正常,但是当 .exe 运行时,我有一个我不想显示的固定命令提示符。
服务.py:
#!/usr/bin/env python
import os
import ctypes
from subprocess import Popen, PIPE
def Mbox(title, text, style):
ctypes.windll.user32.MessageBoxA(0, text, title, style)
python_check = os.path.exists("C:/Python27/python.exe")
g_check = os.path.exists("C:/dev_appserver.py")
if python_check & g_check:
p0 = Popen(['C:/Python27/python.exe', 'C:/dev_appserver.py', '--host', '0.0.0.0', '--port', '8080', 'C:/application'], stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=True)
out, err = p0.communicate("n\n")
else:
Mbox('Notice', 'Launching service failed please make sure C:\Python27\python.exe and C:/dev_appserver.py', 0)
设置.py:
from distutils.core import setup
import py2exe
setup(console=['service.py'])
最佳答案
我刚从这里看到这个:
https://github.com/PySimpleGUI/PySimpleGUI/issues/200#issuecomment-732483328
你可以安装这个库:pip install pywin32
然后,您可以在项目顶部添加这些行:
import win32gui, win32con
hide = win32gui.GetForegroundWindow()
win32gui.ShowWindow(hide, win32con.SW_HIDE)
关于Python - 如何在脚本运行时隐藏 Windows 命令提示符屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24799155/