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

AFoeee
  • 731
  • 7
  • 24

1 Answers1

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.

Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107