[英]How to fix NameError when running Python Script in Windows Command Prompt
[英]Python - how can i hide the windows command prompt screen when the script is running?
当我的 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)
在 setup.py 文件中,您必须编写windows
而不是console
。
像这样:
windows=["service.py"],
options={"py2exe":
{"optimize": 2,
"bundle_files": 0,
"ascii": 0}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.