curses的使用 python

用户输入

while True:
    c = stdscr.getch() # 返回按下的键的ascii码的值,整数型
    if c == ord('p'):
    	PrintDocument()
    elif c == ord('q'):
    	break # 退出循环
    elif c == curses.KEY_HOME:
    	x = y = 0

显示文字

addstr()方法将Python字符串或bytestring作为要显示的值。 字节串的内容按原样发送到终端。 使用窗口encoding属性的值将字符串编码为字节。
addch()方法接受一个字符,该字符可以是长度为1的字符串,长度为1的字节字符串或整数。

curses.wrapper()

import surses, time
def main(stdscr):
    while True:
    	stdscr.clear() # 清除屏幕
    	ch = stdscr.getch() # 获取字符输入
    	if ch == ord('p'):
    	    stdscr.addstr('hello world\n')
    	elif ch == ord('q'):
            break
        stdscr.refresh() # 更新屏幕
        time.sleep(1)
        
curses.wrapper(main)
        

**注意:**curses是默认先y后x,和其他屏幕的先x后y不一样。

猜你喜欢

转载自blog.csdn.net/ganghaod/article/details/83628039