pip install urwid python import urwid import time class ClockApp: def __init__(self): self.text = urwid.Text("") self.status_bar = urwid.Text("Press 'q' to quit") self.main_widget = urwid.Pile([ self.text, urwid.Divider(), self.status_bar ]) self.update_time() def update_time(self): time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) self.text.set_text(time_str) def on_key_press(self, key): if key == 'q': raise urwid.ExitMainLoop() def run(self): loop = urwid.MainLoop(self.main_widget, unhandled_input=self.on_key_press) loop.run() if __name__ == "__main__": app = ClockApp() app.run() python clock_app.py


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