Python-脚本运行时如何隐藏Windows命令提示符屏幕? [英] Python - how can i hide the windows command prompt screen when the script is running?

查看:270
本文介绍了Python-脚本运行时如何隐藏Windows命令提示符屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的python脚本运行时,如何从桌面上删除此黑色命令提示符屏幕?

How can i remove this black command prompt screen from the desktop when my python script is running?

我使用python 2 exe将service.py脚本制作为exe。一切正常,但是当.exe运行时,我有一个不想显示的固定命令提示符。

I made the service.py script into exe using python 2 exe. All worked fine but when the .exe is running i have a fixed command prompt which i do not want to show.

service.py:

service.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)

setup.py:

from distutils.core import setup
import py2exe
setup(console=['service.py'])


推荐答案

在setup.py文件中,您必须编写 windows 而不是 console

In the setup.py file you must write windows instead console.

像这样:

windows=["service.py"],
    options={"py2exe":
       {"optimize": 2,
          "bundle_files": 0,
          "ascii": 0}}

这篇关于Python-脚本运行时如何隐藏Windows命令提示符屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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