- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 curses textpad.Textbox()
函数进行文本输入。到目前为止一切正常,但是,有些键无法识别,包括部分符号 (§) 和所有德语元音符号 (ä/ö/ü)。我猜它与文本编码有某种关系,但我不知道如何解决这个问题。我的德语键盘布局与 input()
配合得很好。
这里是一些最小的例子:
import curses
import curses.textpad as textpad
try:
stdtscr = curses.initscr()
curses.cbreak()
stdtscr.keypad(1)
curses.noecho()
textpad.Textbox(stdtscr).edit()
finally:
curses.nocbreak()
stdtscr.keypad(0)
curses.echo()
curses.endwin()
最佳答案
就像在 C 中一样,您应该初始化语言环境。 Python documentation 中均有说明:
Since version 5.4, the ncurses library decides how to interpret non-ASCII data using the nl_langinfo function. That means that you have to call locale.setlocale() in the application and encode Unicode strings using one of the system’s available encodings.
The library uses the locale which the calling program has
initialized. That is normally done with setlocale:
setlocale(LC_ALL, "");
If the locale is not initialized, the library assumes that
characters are printable as in ISO-8859-1, to work with cer-
tain legacy programs. You should initialize the locale and
not rely on specific details of the library when the locale
has not been setup.
解决后续评论,textpad.py在任何情况下都不期望 UTF-8 输入。本质上它会“验证”它的输入,确定它不是 ASCII 并在不是时忽略它。
Python 的 curses binding为 wgetch
提供接口(interface),其中(使用 ncurses)给出了 UTF-8 的各个字节。 (X/Open Curses 指定了一个不同的函数 wget_wch
,Python 对此没有绑定(bind))。
textpad.py
以通过将字节组装成 Unicode 值来绕过 curses 绑定(bind),但第一步需要 setlocale
。
关于Python curses - textpad.Textbox() 键盘输入不适用于德语变音符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42510606/
我正在查看一本书中的一些源代码并注意到一些代码似乎不在当前的 Python2.7 API 中。根据这段代码,模块 curses 应该有一个名为 LINES 的常量变量和另一个名为 COLS 的常量变量
#include using namespace std; #include //#include int main() { initscr();
我正在尝试在一个使用 Curses 库的简单窗口中实现删除字符。 基本上,窗口是使用以下边框代码创建的: box(local_win, 0 , 0); // Set the border of the
当您启动(n)curses程序时,它将从终端模拟器中删除滚动条,清除屏幕,滚动日志(历史记录)也将消失。当退出程序时,屏幕内容重新出现,滚动条返回,滚动缓冲区返回。 ncurses 是如何实现的?我研
我目前正在尝试为我的程序运行一个小型控制台菜单。我在PyPi curses-menu上找到了curses-menu模块并尝试了我的运气。 curses 菜单有一个 FunctionItem ,它调用
我通过 Linux Mint 的 Xfce 终端 ssh(也尝试过 ssh -t)连接到运行 Rasperian Stretch 的 Raspberry Pi。在 Pi 上,我有一个 Python-C
我正在用 python curses 开发一个应用程序。我正在使用 getch() 方法来获取按下的键。但我可以在屏幕上看到按下的键。我可以随时移动光标,但在光标之后我可以看到用户输入的内容。 当然,
有一个简单的程序: import curses import time window = curses.initscr() curses.cbreak() window.nodelay(True) w
我对 curses 很陌生,但我写了一个可以工作的小 curses 应用程序。但过了一会儿,我注意到我的默认终端设置在 session 期间发生了变化。背景颜色是纯黑色,但我配置了一个透明终端。而且颜
#! /usr/bin/python import curses import curses.textpad as textpad try: mainwindow = curses.inits
我正在尝试为我的 curses 输出添加颜色。然而,挑战在于文本是通过单个长字符串打印的,即 self.all_results。有什么方法可以为字符串的单个部分添加颜色。 def main(self,
我正在尝试在诅咒程序中实现上下滚动,目前我只是想捕捉事件并显示它的数字: MEVENT event; mousemask(ALL_MOUSE_EVENTS, NULL); while (ch != 1
我在使用 Curses 模块检测退格键时遇到了困难。每当我按下 Backspace 键时,返回的字符/字符串都是“^?”,但是我无法通过以下方式检测到它: 如果 str(key) == '^?': 下
我现在非常非常困惑...... 基本上试图声明一个指向curses窗口的全局变量,以便我可以使用调试命令,但它提示AttributeError:'NoneType'对象没有属性'addstr'这意味着
我很难理解 window.timeout() 函数。更具体地说,我正在玩 python 中的“贪吃蛇”游戏: s = curses.initscr() curses.curs_set(0) w = c
我有一个 curses 菜单,我想在上面添加多行描述。 我的代码打开了描述字段,但如果它们不适合该行则不会显示。 Curses 很乐意将多行文本打印为字符串(而不是菜单描述) 关于如何使多行描述有效的
我有以下代码,可让您上下滚动一段文本。每次滚动(即处理用户输入)时,键盘都会按预期更新。然而,在按下第一个键之前,没有任何显示,尽管我正在调用 pad.refresh() 就像我在每次用户输入后所做的
我正在调用 python -m pdb myapp.py,当异常触发时,我通常会返回到 pdb 解释器来调查问题。但是,在我通过 curses.wrapper() 调用并进入 curses 模式后抛出
我使用 curses 为我的应用程序创建了一个简单的 UI,我还使用层级结构(logmain、logmain.child1)等在我的模块中包含日志(日志记录)。 如果发生日志事件,日志将显示在我的 U
我正在学习 Curses 类(class),但无法控制 ENTER 键。到目前为止,这是我的代码: require 'curses' win = Curses::Window.new(0, 0, 0,
我是一名优秀的程序员,十分优秀!