【问题标题】:User interface in PythonPython中的用户界面
【发布时间】:2018-09-23 18:06:24
【问题描述】:

我正在寻找如何用 Python 为我的程序编写一个(相对)友好的用户界面,据我所知,我需要一个名为“curses”的模块。我试图通过 pip 方法安装它,但是 shell 说没有为指定的模块找到匹配的分布。我做错了什么还是什么?模块是否因某种原因被拆除?如果是这样,考虑到我只需要让箭头键为我的程序工作,我还能如何编写这样的界面? 提前致谢

【问题讨论】:

  • 您是否尝试使用curses 编写Windows 程序?如果是这样,来自official documentationThe Windows version of Python doesn’t include the curses module. A ported version called UniCurses is available. You could also try the Console module written by Fredrik Lundh, which doesn’t use the same API as curses but provides cursor-addressable text output and full support for mouse and keyboard input.
  • 好的,你的意思是我实际上不能使用它。伟大的。 Console 模块仅针对 python 2x 编写,我将尝试使用 unicurses。
  • 我建议使用 PyQt5 模块。这是一个用于构建 GUI 的优秀模块
  • @MattLee 我建议使用 IPython 开发 GUI interactively,即使您只使用 tkinter。它确实支持qt,也支持wxgtk

标签: python user-interface python-curses


【解决方案1】:

诅咒是in the standard library。只需导入即可。

如果您使用的是 Windows,您可以尝试安装 unofficial wheel(使用 pip install foo.whl,其中 foo 是 wheel 文件的名称——下载与您的 Python 安装匹配的文件)。


这是 Python 2.7 64 位的示例安装。

C:\>py -2 -m pip install curses-2.2-cp27-cp27m-win_amd64.whl

这是一个简单的诅咒“hello world”来测试它。

import curses

@curses.wrapper
def main(stdscr):
  stdscr.clear()
  stdscr.addstr(5, 20, 'hello world')
  stdscr.getch()

保存到像cursestest.py 这样的文件,然后像这样运行它

C:\>py -2 cursestest.py

我在我的 Windows 机器上测试了上述内容,它工作正常。

【讨论】:

  • 显然不在windows版本上
  • @MicheleBastione 所以你在 Windows 上。你试过先安装轮子吗?
  • 是的,但它不会改变任何东西
  • 好的,它已经安装好了,我可以导入模块,但显然官方文档中的功能都不起作用。我该怎么办?
  • @MicheleBastione 确保您安装的轮子与您使用的 Python 版本相匹配(版本号如 2.7 和 32 或 64 位。)并使用在该 Python 上运行的 pip 进行安装。试试上面的“hello world”脚本。
猜你喜欢
  • 1970-01-01
  • 2015-07-13
  • 1970-01-01
  • 1970-01-01
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 1970-01-01
相关资源
最近更新 更多