import urwid class Model: def __init__(self): self.data = "Hello, World!" class View(urwid.WidgetWrap): def __init__(self, model): self.model = model self.text = urwid.Text(self.model.data) super().__init__(self.text) def update(self): self.text.set_text(self.model.data) class Controller: def __init__(self, model): self.model = model def handle_input(self, input): if input == 'q': raise urwid.ExitMainLoop() elif input == 'u': self.model.data = "Updated data" self.view.update() model = Model() view = View(model) controller = Controller(model) loop = urwid.MainLoop(view, unhandled_input=controller.handle_input) loop.run()


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