在 ncurses 文本板中输入时,字符会打印两次

问题描述

我正在使用 ncurses 在 python 中创建一个简单的用户名输入字段。我修改了文档中的代码,发现当我输入单个字符时,比如 w,它会在文本键盘显示两个相同的字符,而不是给我单个字符 ({{1} } 而不是 ww)。所以我以为我把编码搞砸了,然后对例子中的textpad进行了1对1的克隆,出现了同样的问题。

预期的结果如下(我每次输入一个字符都会向左移动光标得到它)

image1

我实际得到的结果如下:

image2

我尝试复制示例,重新安装 ncurses 和 Python,我尝试使用 allacrity 而不是我通常使用的,但它们都不起作用。

文件代码如下:

w

编辑:我找到了解决方案。实际问题是在登录函数中,import curses from curses.textpad import TextBox,rectangle screen = curses.initscr() def center_text(stdscr,text,offset): # Gets the height and lenght of the screen scr_rows,scr_cols = stdscr.getmaxyx() # Gets the center of the screen mid_row = int(scr_rows / 2) mid_col = int(scr_cols / 2) # half of the lenght of the text mes_len_half = int(len(text)+10 / 2) x_pos = mid_col - mes_len_half # prints the text in the middle stdscr.addstr(mid_row+offset,x_pos,text) stdscr.refresh() # returns some data for the login section return mid_row+offset,text def login(stdscr): unamerow,unamecol,text = center_text(screen,"Username: ",0) # Creates the rectangle around the area,and the window for input editBox = curses.newwin(1,10,unamerow,unamecol+len(text)) rectangle(stdscr,unamerow-1,unamecol-1,unamerow+1,unamecol+len(text)+10) stdscr.refresh() # manages the input window,and turns it into a textBox Box = TextBox(editBox) Box.edit() uname = Box.gather() return uname if __name__ == "__main__": uname = login(screen) curses.endwin() print(uname) 处于打开状态,因此文本垫打印了字符,回显也是如此。所以我只是在函数的开头添加curses.echo()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)