text = urwid.Text(('dark green', 'Hello, World!')) from urwid.escape import URWID_ESCAPE_START, URWID_ESCAPE text = urwid.Text((URWID_ESCAPE_START + "38;5;" + str(color_index) + "m", 'Hello, World!')) def generate_colored_text(text, color_index): return URWID_ESCAPE(38, 5, color_index) + text text = urwid.Text(generate_colored_text('Hello, World!', color_index)) 3. True color text = urwid.Text(('rgb', color, 'Hello, World!')) text = urwid.Text((urwid.BOLD, 'Hello, World!')) text = urwid.Text((urwid.ITALIC, 'Hello, World!')) text = urwid.Text((urwid.UNDERLINE, 'Hello, World!')) import urwid from urwid.escape import URWID_ESCAPE_START, URWID_ESCAPE def generate_colored_text(text, color_index): return URWID_ESCAPE(38, 5, color_index) + text palette = [ ('body', 'black', 'light gray'), ('bold', 'black', 'light gray', 'bold'), ('italic', 'black', 'light gray', 'italic'), ('underline', 'black', 'light gray', 'underline'), ('red', 'dark red', 'light gray'), ('green', 'dark green', 'light gray'), ('blue', 'dark blue', 'light gray'), ] text1 = urwid.Text(('bold', 'Bold Text')) text2 = urwid.Text(('italic', 'Italic Text')) text3 = urwid.Text(('underline', 'Underlined Text')) text4 = urwid.Text(('red', 'Text with Color')) text5 = urwid.Text((URWID_ESCAPE_START + "38;5;46m", 'Text with 256-color')) pile = urwid.Pile([text1, text2, text3, text4, text5]) fill = urwid.Filler(pile, 'top') loop = urwid.MainLoop(fill, palette) loop.run()


上一篇:
下一篇:
切换中文