Are there any toolkit libraries for curses with Python bindings?

10,180

Solution 1

Urwid is the best library to work with curses and python that I know.

Altenatively, you might find also interesting snack (newt-based library).

For more information, please have a look at this question.

Solution 2

npyscreen

Npyscreen is a Python widget library and application framework for programming terminal or console applications. It is built on top of ncurses, which is part of the standard library.

The focus of this library is to provide a rapid way to develop console applications. In general, adding a control to the screen requires only one line of code.

This framework should be powerful enough to create everything from quick, simple programs to complex, multi-screen applications.

npyscreen screenshot

#!/usr/bin/env python
# encoding: utf-8

import npyscreen
class TestApp(npyscreen.NPSApp):
    def main(self):
        # These lines create the form and populate it with widgets.
        # A fairly complex screen in only 8 or so lines of code - a line for each control.
        F  = npyscreen.Form(name = "Welcome to Npyscreen",)
        t  = F.add(npyscreen.TitleText, name = "Text:",)
        fn = F.add(npyscreen.TitleFilename, name = "Filename:")
        fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:")
        dt = F.add(npyscreen.TitleDateCombo, name = "Date:")
        s  = F.add(npyscreen.TitleSlider, out_of=12, name = "Slider")
        ml = F.add(npyscreen.MultiLineEdit,
               value = """try typing here!\nMutiline text, press ^R to reformat.\n""",
               max_height=5, rely=9)
        ms = F.add(npyscreen.TitleSelectOne, max_height=4, value = [1,], name="Pick One",
                values = ["Option1","Option2","Option3"], scroll_exit=True)
        ms2= F.add(npyscreen.TitleMultiSelect, max_height =-2, value = [1,], name="Pick Several",
                values = ["Option1","Option2","Option3"], scroll_exit=True)

        # This lets the user interact with the Form.
        F.edit()

        print(ms.get_selected_objects())

if __name__ == "__main__":
    App = TestApp()
    App.run()
Share:
10,180
Llamageddon
Author by

Llamageddon

I enjoy programming, and hold an interest in engineering as well, although I can only call myself knowledgeable about the first. I enjoy the theory and design behind programming languages, and I quite enjoy thinking of all kinds of things.

Updated on July 18, 2022

Comments

  • Llamageddon
    Llamageddon almost 2 years

    I'm writing a text-based hex viewer for fun and usefulness(I intend to add syntax highlighting for many different filetypes), and am wondering if there are any curses toolkits I could use.

    I will probably write something myself anyway as to familiarize myself with the way gui toolkits work, but it would be nice to know of useful libraries for future reference for myself and others.

  • Llamageddon
    Llamageddon almost 9 years
    Since it seems like it's your code - it really needs some code examples badly, and honestly, the repo name is kind of off-putting as well. Either way, thanks for the answer, and welcome to Stack Overflow :)
  • Richard Gordon
    Richard Gordon almost 9 years
    Yes it's my code and in the GitHub repository you will find not just the source code for the API but also that for the examples used to test and demonstrate it. Since I'm emulating the wxPython API, you can look at the introduction and tutorial for wxPython. My Announcement provides an overview of the distribution and its usage. The Python 2x code is large and complex (over 100,000 lines of executable Python. My Brochure provides screenshots; My Notebooks include an Introduction and engineering style specification, design and user documents.
  • Shadi
    Shadi over 4 years
    snack link is broken
  • jcollado
    jcollado over 4 years
    @shadi It looks like snack might now be included in newt itself: github.com/mlichvar/newt/blob/master/snack.py
  • Shadi
    Shadi over 4 years
    I see. The tutorial linked on the wiki page for newt is also broken (tutorial link) and the newt homepage doesn't have any documentation or links. Any idea where I can find docs for newt?
  • jcollado
    jcollado over 4 years
    @shadi In the internet archive you can still find a backup version of that tutorial? web.archive.org/web/20170124075941/http://gnewt.sourceforge.‌​net/…