[Urwid] ListBox, focus and colors

Ian Ward ian at excess.org
Fri Apr 28 08:35:55 EDT 2006


Bernardo Torres wrote:
> In the tutorial, there's a ListBox that changes colors when focus
> changes. I've used this:
> urwid.AttrWrap(urwid.Text(mod), 'module', 'focustext') in the ListBox,
> thinking 'focustext' would be used in focus, but none happened.

I think the problem here is that Text widets are not selectable, so they 
won't become the focus.  You might try something like this:

class ModuleWidget(urwid.WidgetWrap):
     def __init__(self, mod):
         w = urwid.Text(mod)
         w = urwid.AttrWrap(w, 'module', 'focustext')
         urwid.WidgetWrap.__init__(self, w)
     def selectable(self):
         return True

and in your listbox use:
ModuleWidget( mod )

This is a custom widget that is selectable and will appear the way you 
intended.  You can also add a "keypress" method to this class to handle 
input on your widget.

Regards,
Ian




More information about the Urwid mailing list