The following example (taken from here: http://urwid.org/tutorial/index.html) shows how to pass key values to a callback function show_or_exit
.
import urwid
def show_or_exit(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
txt.set_text(repr(key))
txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill, unhandled_input=show_or_exit)
loop.run()
How can I pass another argument to show_or_exit
with this callback that depend on the state of the system, that would be something like this?
...: param_val = 4
...:
...: def my_fun():
...: #do something
...: return param_val
...:
...: def show_or_exit(key, param_val):
...: if key in ('q', 'Q'):
...: raise urwid.ExitMainLoop()
...: txt.set_text(repr(key))
...: do_something(param_val)
...:
...: txt = urwid.Text(u"Hello World")
...: fill = urwid.Filler(txt, 'top')
...: loop = urwid.MainLoop(fill, unhandled_input=show_or_exit)
...: loop.run()