[Urwid] Enable/disable buttons?

Ian Ward ian at excess.org
Mon Dec 7 08:47:38 EST 2009

Yasir Assam wrote:
> ok = urwid.Button("OK")
> I want to be able to disable the OK button depending on what's being
> input. By "disable" I stopping the cursor from moving it to it when I
> use the arrow keys to move focus around.
> Is there an easy way to do this?

Yes, the selectable() method on widgets determines whether the cursor
will move to a widget, so you could make a Button subclass that returns
False from selectable() when the button should not be selectable.

You will also have to intercept mouse clicks for it to be a complete
solution.  Look at the code for the Button class, it's not very complicated.



More information about the Urwid mailing list