DEV Community

MrRobot
MrRobot

Posted on

Npyscreen – Text-Based User Interface Framework in python

Npyscreen is a Python framework for creating text-based user interfaces (TUIs) that run directly inside the terminal. It’s built on top of the curses library and provides widgets like forms, buttons, lists, and input fields to help developers build interactive console applications quickly. It’s perfect for dashboards, setup tools, and CLI-based management systems.


Installation:

pip install npyscreen
Enter fullscreen mode Exit fullscreen mode

Example usage:

import npyscreen

class MyApp(npyscreen.NPSAppManaged):
    def onStart(self):
        self.addForm("MAIN", MainForm)

class MainForm(npyscreen.Form):
    def create(self):
        self.name = self.add(npyscreen.TitleText, name="Name:")
        self.age = self.add(npyscreen.TitleText, name="Age:")
        self.add(npyscreen.ButtonPress, name="Submit", when_pressed_function=self.submit)

    def submit(self):
        npyscreen.notify_confirm(f"Hello {self.name.value}, age {self.age.value}!", title="Result")

if __name__ == "__main__":
    MyApp().run()
Enter fullscreen mode Exit fullscreen mode

PyPI page: https://pypi.org/project/npyscreen/
GitHub page: https://github.com/npcole/npyscreen


3 Project Ideas:

  1. Build a terminal-based task manager or to-do list.
  2. Create a server monitoring dashboard inside the terminal.
  3. Develop an interactive setup wizard for command-line applications.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.