1说明: 1。1Rich库,是python的一个库文件,可以在终端显示多彩的、格式化、富文本的文字、表格和进度条。 1。2环境: 华为笔记本电脑、深度deepinlinux操作系统、python3。8和微软vscode编辑器。 2Rich库: 2。1官网:github地址https:github。comwillmcguganrich学习文档https:rich。readthedocs。ioenlatestindex。html 2。2安装:pipinstallrich本机安装sudopip3。8installrich 2。3提示报错:WARNING:Thescriptcmarkisinstalledinusrlocalpython3。8binwhichisnotonPATH。ConsideraddingthisdirectorytoPATHor,ifyouprefertosuppressthiswarning,usenowarnscriptlocation。WARNING:Thescriptpypprintisinstalledinusrlocalpython3。8binwhichisnotonPATH。ConsideraddingthisdirectorytoPATHor,ifyouprefertosuppressthiswarning,usenowarnscriptlocation。 2。4其实就是没有进行软连接,本机软连接示范:sudolnsusrlocalpython3。8bincmarkusrbincmarksudolnsusrlocalpython3。8binpypprintusrbinpypprint 3进度条: 3。1比较有特色。 3。2代码:progress1。pyfromrich。progressimporttrackimporttimeforstepintrack(range(30)):print(WelovePython!)time。sleep(0。5) 效果图1: 3。3代码:progress2。pyfromrich。progressimportProgressimporttimewithProgress()asprogress:task1progress。addtask(〔red〕Downloading。。。,total1000)task2progress。addtask(〔green〕Processing。。。,total1000)task3progress。addtask(〔cyan〕Cooking。。。,total1000)whilenotprogress。finished:progress。update(task1,advance0。5)progress。update(task2,advance0。3)progress。update(task3,advance0。9)time。sleep(0。02) 效果图2: 4终端彩色的、富文本打印: 4。1代码:方法一fromrichimportprint对world进行bold粗体,颜色magentaprint(Hello〔boldmagenta〕World〔boldmagenta〕!)print(〔boldmagenta〕HelloWorld!〔boldmagenta〕)方法二fromrich。consoleimportConsoleconsoleConsole()console。print(Hello,World!)普通输出整体字体和颜色设置console。print(Hello,World!,styleboldmagenta)代表换行〔u〕is〔u〕代表下划线,〔i〕way〔i〕代表斜体console。print(Wherethereisa〔boldcyan〕Will〔boldcyan〕there〔u〕is〔u〕a〔i〕way〔i〕。) 4。2效果图 5表格终端输出: 5。1代码:方法一fromrich。consoleimportConsolefromrich。tableimportColumn,TableconsoleConsole()表头设置headerstyleboldmagentatableTable(showheaderTrue,headerstyleboldmagenta)列table。addcolumn(Date,styledim,width12)table。addcolumn(Title)table。addcolumn(ProductionBudget,justifyright)table。addcolumn(BoxOffice,justifyright)行table。addrow(Dev20,2019,StarWars:TheRiseofSkywalker,275,000,000,375,126,118)table。addrow(May25,2018,〔red〕Solo〔red〕:AStarWarsStory,275,000,000,393,151,347,)table。addrow(Dec15,2017,StarWarsEp。VIII:TheLastJedi,262,000,000,〔bold〕1,332,539,889〔bold〕,)console。print(table)方法二:更简洁fromrichimportprintfromrich。tableimportColumn,Table表头设置headerstyleboldmagentatableTable(showheaderTrue,headerstyleboldmagenta)列table。addcolumn(Date,styledim,width12)table。addcolumn(Title)table。addcolumn(ProductionBudget,justifyright)table。addcolumn(BoxOffice,justifyright)行table。addrow(Dev20,2019,StarWars:TheRiseofSkywalker,275,000,000,375,126,118)table。addrow(May25,2018,〔red〕Solo〔red〕:AStarWarsStory,275,000,000,393,151,347,)table。addrow(Dec15,2017,StarWarsEp。VIII:TheLastJedi,262,000,000,〔bold〕1,332,539,889〔bold〕,)print(table) 5。2图: 自己整理并分享出来,喜欢的点赞、转发和收藏。