summaryrefslogtreecommitdiff
path: root/docs/tutorial/edit.py
blob: b7d98170def45387aaf086ccf3f680e4b5231e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import urwid

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

class QuestionBox(urwid.Filler):
    def keypress(self, size, key):
        if key != 'enter':
            return super(QuestionBox, self).keypress(size, key)
        self.original_widget = urwid.Text(
            u"Nice to meet you,\n%s.\n\nPress Q to exit." %
            edit.edit_text)

edit = urwid.Edit(u"What is your name?\n")
fill = QuestionBox(edit)
loop = urwid.MainLoop(fill, unhandled_input=exit_on_q)
loop.run()