【发布时间】:2013-03-29 04:43:31
【问题描述】:
我正在使用 Python 2.7 和 colorama 0.2.5。我正在调用一个打印一些彩色文本的方法:
from colorama import Fore
from colorama import Style
from colorama import init
def sendData(self):
print("Sending data..."),
sys.stdout.flush()
self.browser.submit()
print(Style.BRIGHT + "[ " + Fore.GREEN + "OK" + Fore.RESET + " ]" + Style.RESET_ALL) ## Prints coloured text
init()
sendData()
这部分代码在 GUI 应用程序(使用 pyqt 制作)中为用户提供了一些终端输出。
使用 Python 解释器运行此脚本的工作方式在 Ubuntu 12.04 和 Windows 7 上都是如此。但是,当我使用 PyInstaller(使用 --onefile 标志)将其编译为一个可执行文件时,情况发生了变化:
- 在 Ubuntu 12.04 上,从终端运行可执行文件时,我得到彩色终端输出,这是我想要的样子。
- 在 Windows 7 上,从
cmd运行可执行文件时,GUI 运行良好,但我没有得到终端输出。
如果有帮助,我在 PyInstaller 命令中给出的标志是-F(一个文件)和-w(窗口模式)。
如何让可执行文件在 Windows 7 中以 cmd 打印彩色文本?
【问题讨论】:
标签: python cmd executable output colorama