用于轻松创建看起来像Linux顶级程序的文本接口的库。
topshape的Python项目详细描述
用于轻松创建看起来像Linux顶级程序的文本接口的库。
它建立在urwid之上,但不需要了解urwid本身。
- 自由软件:麻省理工学院许可证
- 文档:https://topshape.readthedocs.io。
- 支持的Python版本:2.7、3.3、3.4、3.5、3.6
快速启动
下面是一个如何使用topshape的示例:
fromtopshapeimportTopShape# The columns are a list (or tuple) of dictionaries. Each# dictionary defines a column in the bodycolumns=({'label':'header1'},{'label':'header2'},{'label':'header3'})# The body function will be passed as a callback that must# return a 2-dimensional array everytime it's called.defbody():return[[str(i*j)foriinrange(3)]forjinrange(10)]# The header function will be passed as a callback that must# return a string everytime it's called.defheader():return'This is the header!'# The footer function will be passed as a callback that must# return a string everytime it's called.deffooter():return'This is the footer!'defhandle_q(app):app.exit()defhandle_f(app,answer):# do something with the answer# ...# key_map maps keys pressed to callbackskey_map={'q':handle_q,'f':(handle_f,'Enter some text here:'}app=TopShape.create_app(columns,body,header,footer,key_mapping=key_map)app.run()
输出:
输出(等待用户输入):
还有一个更完整的例子here,它是linux top程序的克隆。
屏幕截图:
学分
这个包是用Cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。