pip install urwid python import urwid def exit_on_q(key): if key in ('q', 'Q'): raise urwid.ExitMainLoop() data = [{'city': 'Beijing', 'temperature': '20°C'}, {'city': 'Shanghai', 'temperature': '25°C'}, {'city': 'Guangzhou', 'temperature': '28°C'}, {'city': 'Chengdu', 'temperature': '18°C'}, {'city': 'Hangzhou', 'temperature': '22°C'}] headers = ['City', 'Temperature'] table_data = [urwid.Text(headers)] for d in data: row = [urwid.Text(d['city']), urwid.Text(d['temperature'])] table_data.append(urwid.Columns(row)) table = urwid.Pile(table_data) wrapped_table = urwid.Padding(table, left=2, right=2) fill = urwid.Filler(wrapped_table, valign='top', height=('relative', 80)) loop = urwid.MainLoop(fill, unhandled_input=exit_on_q) loop.run()


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