我一直在阅读有关使用 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/