windows python中用于跨平台控制台应用程序的类似curses的库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1244897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:57:39  来源:igfitidea点击:

curses-like library for cross-platform console app in python

pythonwindowslinuxconsolencurses

提问by andreas-h

I'm looking into developing a console application in python which should be able to run under Windows as well as Linux. For this, I'd really like to use a high-level console library like curses. However, as far as I know, curses is not available on Windows.

我正在研究在 python 中开发一个控制台应用程序,它应该能够在 Windows 和 Linux 下运行。为此,我真的很想使用像curses 这样的高级控制台库。但是,据我所知,curses 在 Windows 上不可用。

What other options do I have? Unfortunately, using cygwin under Windows is not an option...

我还有什么其他选择?不幸的是,在 Windows 下使用 cygwin 不是一种选择......

Thanks for your help!

谢谢你的帮助!

采纳答案by ehempel

There is a wcurses. I've never tried it but it may meet your needs. It sounds like it doesn't have full curses compatibility, but may be close enough. Also it might not be using the DOS terminal, but opening a GUI window and drawing monospaced text inside.

有一个wcurses。我从未尝试过,但它可能会满足您的需求。听起来它没有完全的诅咒兼容性,但可能足够接近。它也可能不是使用 DOS 终端,而是打开一个 GUI 窗口并在其中绘制等宽文本。

Other windows text mode options are:

其他 Windows 文本模式选项是:

I believe both are windows only.

我相信两者都只是窗户。

回答by Bastien Léonard

PDCursesworks on Windows, but I don't know any Python wrapper. I wonder whether the curses module could be implemented on Windows with PDCurses?

PDCurses适用于 Windows,但我不知道任何 Python 包装器。我想知道curses 模块是否可以在Windows 上使用PDCurses 实现?

回答by Peter Brittain

I recently hit this issue for a package I was putting together (https://github.com/peterbrittain/asciimatics). I wasn't very happy with the solutions that required you to install (or worse) build separate binary executables like PDCurses or cygwin, so I created a unified API that provides console colours, cursor positioning and keyboard & mouse input for Windows, OSX and UNIX platforms.

我最近遇到了这个问题,因为我正在整理一个包(https://github.com/peterbrittain/asciimatics)。我对要求您安装(或更糟)构建单独的二进制可执行文件(如 PDCurses 或 cygwin)的解决方案不太满意,因此我创建了一个统一的 API,为 Windows、OSX 和UNIX 平台。

This is now live and has been tested on CentOS 6/7 and Windows 7/8/10 and OSX 10.11. You can install it from PYPI using pip and then use the Screenclass to control your console. As you can see from the project gallery, it should provide all your console needs, but if you need some extra features, please post an enhancement request on GitHub and I'll see what I can do.

它现已上线并已在 CentOS 6/7 和 Windows 7/8/10 和 OSX 10.11 上进行测试。您可以使用 pip 从 PYPI 安装它,然后使用Screen该类来控制您的控制台。正如您从项目库中看到的,它应该提供您所有的控制台需求,但是如果您需要一些额外的功能,请在 GitHub 上发布增强请求,我会看看我能做些什么。

回答by Gringo Suave

I don't know why people answer in question comments, but debustad is right, there is a prebuilt curses for Windows:

我不知道为什么人们在问题评论中回答,但 debustad 是对的,Windows 有一个预先构建的诅咒:

Note lots of other helpful libraries there too. After doing so, install pip and the (lesser known but excellent) bpythoninteractive interpreter to try it out immediately:

请注意那里还有许多其他有用的库。这样做之后,安装 pip 和(鲜为人知但非常出色的)bpython交互式解释器以立即试用:

pip install bpython

I also recommend the Urwid libraryfor something higher-level. Never tried it on Windows, but it should be possiblewith one of the curses packages.

我还推荐Urwid 库以获得更高级别的内容。从未在 Windows 上尝试过,但使用 Curses 包之一应该可以

回答by nosklo

develop two interfaces for your program, a text console ui and a graphical ui. Make the console one work only on linux. Nobody on windows uses text console apps.

为您的程序开发两个界面,一个文本控制台 ui 和一个图形 ui。使控制台仅在 linux 上工作。Windows 上没有人使用文本控制台应用程序。