是否有任何用于Python绑定的curses的工具包库?

Lla*_*don 6 python curses user-interface toolkit

我正在编写一个基于文本的十六进制查看器,以获得乐趣和实用性(我打算为许多不同的文件类型添加语法突出显示),并且我想知道是否有任何我可以使用的curses工具包.

我可能会自己写一些东西,以便熟悉gui工具包的工作方式,但是知道有用的库以供将来参考我自己和其他人会很好.

jco*_*ado 9

Urwid是我知道的最好的curses和python库.

另外,您可能会发现有趣的小吃(基于newt的库).

有关详细信息,请查看此问题.


Ser*_*ndt 6

屏幕截图

Npyscreen是用于编程终端或控制台应用程序的 Python 小部件库和应用程序框架。它建立在 之上ncurses,它是标准库的一部分。

该库的重点是提供一种快速开发控制台应用程序的方法。一般来说,向屏幕添加控件只需要一行代码。

这个框架应该足够强大,可以创建从快速、简单的程序到复杂的多屏幕应用程序的所有内容。

npyscreen 截图

#!/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()
Run Code Online (Sandbox Code Playgroud)