由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

npyscreen

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图1
开发terminal平台软件
Developing terminal platform apps

1 Quick Start

  1. ##!/usr/bin/env python3.7
  2. ## encoding: utf-8
  3. import npyscreen
  4. class TestApp(npyscreen.NPSApp):
  5. def main(self):
  6. # These lines create the form and populate it with widgets.
  7. # A fairly complex screen in only 8 or so lines of code - a line for each control.
  8. F = npyscreen.Form(name = "Welcome to Npyscreen",)
  9. t = F.add(npyscreen.TitleText, name = "Text:",)
  10. fn = F.add(npyscreen.TitleFilename, name = "Filename:")
  11. fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:")
  12. dt = F.add(npyscreen.TitleDateCombo, name = "Date:")
  13. s = F.add(npyscreen.TitleSlider, out_of=12, name = "Slider")
  14. ml = F.add(npyscreen.MultiLineEdit,
  15. value = """try typing here!\nMutiline text, press ^R to reformat.\n""",
  16. max_height=5, rely=9)
  17. ms = F.add(npyscreen.TitleSelectOne, max_height=4, value = [1,], name="Pick One",
  18. values = ["Option1","Option2","Option3"], scroll_exit=True)
  19. ms2= F.add(npyscreen.TitleMultiSelect, max_height =-2, value = [1,], name="Pick Several",
  20. values = ["Option1","Option2","Option3"], scroll_exit=True)
  21. # This lets the user interact with the Form.
  22. F.edit()
  23. print(ms.get_selected_objects())
  24. if __name__ == "__main__":
  25. App = TestApp()
  26. App.run()

效果:
npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图2

Features

Input

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图3

Path segestion

Path1:

Tab 键激活

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图4

Path2:

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图5

Date

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图6

Progress bar

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图7

Selection

npyscreen | 一個簡單的Python  TUI 庫的簡單介紹 - 图8
ptop is npyscreen apps


Enjoy~

本文由Python腳本GitHub/語雀自動更新

由於語法渲染問題而影響閱讀體驗, 請移步博客閱讀~
本文GitPage地址

GitHub: Karobben
Blog:Karobben
BiliBili:史上最不正經的生物狗