2

I'm wondering if the python libary urwid includes an input option that behaves like a GUI text field.

By this I mean that,

  • the input option remains editable after the input.
  • individual fields can be filled out in any order.

Here is a simple example of Swing's JTextField:

enter image description here

1 Answer 1

2

The input text equivalent in urwid is the Edit widget, here is an example of how you can use it:

#!/usr/bin/env python

from __future__ import print_function, absolute_import, division
import urwid


def show_or_exit(key):
    if key in ('q', 'Q', 'esc'):
        raise urwid.ExitMainLoop()

def name_changed(w, x):
    header.set_text('Hello % s!' % x)


if __name__ == '__main__':
    name_edit = urwid.Edit("Name: ")
    header = urwid.Text('Fill your details')
    widget = urwid.Pile([
        urwid.Padding(header, 'center', width=('relative', 6)),
        name_edit,
        urwid.Edit('Address: '),
    ])
    urwid.connect_signal(name_edit, 'change', name_changed)

    widget = urwid.Filler(widget, 'top')
    loop = urwid.MainLoop(widget, unhandled_input=show_or_exit)
    loop.run()

If you try it out, you can see that both fields remain editable and can be filled in any order.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.