Hey Paul,

you can use a listbox for that. Look at the tutorial part 2.3 "Modifying 
ListBox Content", it actually do what you want

cheers

On 27/01/2011 21:04, Paul Waring wrote:
> I'm trying to build a simple console application using urwid which
> performs the following task:
>
> 1. Print menu ("Menu: ")
> 2. User presses a letter or number key (everything else can be discarded)
> 3. Print some text based on key pressed (quit if 'q')
> 4. GOTO 1
>
> At the moment I've got the following code, largely taken from the tutorial:
>
> import urwid
>
> def unknown_input(input):
>     if input in ('q', 'Q'):
>       raise urwid.ExitMainLoop()
>     elif input in ('l', 'L'):
>       txt.set_text('list')
>     else:
>       txt.set_text('unknown option')
>
> txt = urwid.Text('Menu: ')
> fill = urwid.Filler(txt, 'top')
>
> loop = urwid.MainLoop(fill, unhandled_input=unknown_input)
> loop.run()
>
> This *almost* does what I want, except txt.set_text() overwrites the one
> line of text every time, whereas I want to print below the existing text
> to get output like the following:
>
> Menu: L
> "You pressed L"
> Menu: q
> <quit>
>
> I could just use txt.set_text(txt.get_text() + 'new text') but I suspect
> that would end up creating a large string eventually and I don't care
> about content once it has disappeared off the top of the screen.
>
> Should I be using a different object instead of Text? I don't want users
> to be able to scroll back so a ListBox doesn't really fit (users can
> only press a key at the menu).
>
> Thanks,
>
> Paul
>


_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to