python
import urwid
screen = urwid.raw_display.Screen()
# ...
python
text_widget = urwid.Text("Hello, World!")
python
urwid.MainLoop(top_widget, screen).run()
python
class MyWidget(urwid.WidgetWrap):
def __init__(self, text):
self.text_widget = urwid.Text(text)
self.wrapped_widget = urwid.BoxAdapter(self.text_widget, height=10, focus=False)
super().__init__(self.wrapped_widget)
python
class MyLayout(urwid.WidgetWrap):
def __init__(self, widgets):
self.pile = urwid.Pile(widgets)
self.fill = urwid.Filler(self.pile)
self.top_widget = urwid.Padding(self.fill)
super().__init__(self.top_widget)
python
my_widget = MyWidget("Hello, Custom Widget!")
my_layout = MyLayout([my_widget])
urwid.MainLoop(my_layout, screen).run()