Python colorama无法与输入配合使用?

编程入门 行业动态 更新时间:2024-10-28 16:25:52
本文介绍了Python colorama无法与输入配合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

今天终于让colorama可以工作了,并且在打印字符串时效果很好,但是当我尝试将colorama与输入配合使用时,我遇到了每个人似乎都遇到的常见错误.

Finally got colorama working today, and it works excellent when printing strings, but I got the common error everyone seems to get when I attempted to use colorama with input.

这是我的代码:

launch = input(Fore.GREEN + "Launch attack?(Y/N): ")

输出屏幕截图:

推荐答案

在我的系统上,input()使用 if 添加的颜色

On my system, input() works with colors if you add

import sphinx.quickstart

到您的模块.

这是完整的代码.

from colorama import Fore import colorama import sphinx.quickstart colorama.init() launch = input(Fore.GREEN + "Launch attack? (Y/N): ")

(这导致两个问题:

  • 为什么一开始它不起作用?
  • 真正的原因是什么? –某些人可能想深入了解狮身人面像的源代码.)
  • N.B.如果您通过 Git Bash 中的winpty运行python,请设置convert.

    N.B. if you run python via winpty from Git Bash, set convert.

    colorama.init(convert=True)

    否则,当前版本不会显示颜色.

    Otherwise, you do not get color with the current versions.

    更多推荐

    Python colorama无法与输入配合使用?

    本文发布于:2023-11-24 03:06:28,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1623749.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Python   colorama

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!