python - 如何在 Python curses 库中使用扩展字符?

标签 python curses

我一直在阅读有关使用 Python 进行 Curses 编程的教程,其中很多都提到了使用扩展字符(例如画线符号)的能力。它们是大于 255 个字符,并且 curses 库知道如何以当前终端字体显示它们。

一些教程说你可以这样使用它:

c = ACS_ULCORNER

...有些人说您可以这样使用它:

c = curses.ACS_ULCORNER

(这应该是一个盒子的左上角,就像一个垂直翻转的L)

不管怎样,不管我用什么方法,名字都没有定义,程序就失败了。我尝试了“import curses”和“from curses import *”,但都不起作用。

Curses 的 window() 函数使用了这些字符,所以我什至尝试在我的盒子上四处寻找源代码以查看是如何实现的,但我无法在任何地方找到它。

最佳答案

您必须将您的本地设置为全部,然后将您的输出编码为 utf-8,如下所示:

import curses
import locale

locale.setlocale(locale.LC_ALL, '')    # set your locale

scr = curses.initscr()
scr.clear()
scr.addstr(0, 0, u'\u3042'.encode('utf-8'))
scr.refresh()
# here implement simple code to wait for user input to quit
scr.endwin()

输出: あ

关于python - 如何在 Python curses 库中使用扩展字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1279341/

相关文章:

python - 当 xterm 调整大小时,getch() 未返回 KEY_RESIZE

Python 诅咒 : addstr() from file prints blanks for the remainder of the line

python - 在不清除终端的情况下在 Python 中诅咒窗口

python - 在绘制图像之前打印文本 (matplotlib/imageio)

python - 如何在 OpenERP 7 中修改 css?

python - 根据前缀限制列表中字符串的出现

c - getyx 返回 -1 -1

python - Pandas:根据重复索引值加速 df.loc

python - Plotly/Dash 以流畅的动画显示实时数据

Python 控制台应用程序 - 在输入行上方输出