有没有人有使用curses.textpad.Textbox小部件编辑现有文本的实用示例?当然,这是在Linux终端(例如xterm)中实现的。
发布于 2012-10-26 09:07:11
我发现urwid包中的Edit小部件足以满足我的需求。这不是Textpad小部件,而是一些不同的小部件。不管怎么说,urwid包总体上更好。然而,它仍然不是没有痛苦的。Edit小部件确实允许插入文本,但不允许覆盖(使用Ins键切换),但这不是什么大问题。
发布于 2011-03-16 21:43:12
找到这个有几分钟了
import curses
import curses.textpad
stdscr = curses.initscr()
# don't echo key strokes on the screen
curses.noecho()
# read keystrokes instantly, without waiting for enter to ne pressed
curses.cbreak()
# enable keypad mode
stdscr.keypad(1)
stdscr.clear()
stdscr.refresh()
win = curses.newwin(5, 60, 5, 10)
tb = curses.textpad.Textbox(win)
text = tb.edit()
curses.beep()
win.addstr(4,1,text.encode('utf_8'))我还做了一个函数来制作一个文本框:
def maketextbox(h,w,y,x,value="",deco=None,underlineChr=curses.ACS_HLINE,textColorpair=0,decoColorpair=0):
nw = curses.newwin(h,w,y,x)
txtbox = curses.textpad.Textbox(nw)
if deco=="frame":
screen.attron(decoColorpair)
curses.textpad.rectangle(screen,y-1,x-1,y+h,x+w)
screen.attroff(decoColorpair)
elif deco=="underline":
screen.hline(y+1,x,underlineChr,w,decoColorpair)
nw.addstr(0,0,value,textColorpair)
nw.attron(textColorpair)
screen.refresh()
return txtbox要使用它,只需执行以下操作:
foo = maketextbox(1,40, 10,20,"foo",deco="underline",textColorpair=curses.color_pair(0),decoColorpair=curses.color_pair(1))
text = foo.edit()发布于 2012-01-07 03:40:07
textpad.Textbox(win, insert_mode=True)提供了基本的插入支持。不过,需要添加退格键。
https://stackoverflow.com/questions/4581441
复制相似问题