作为 Python 和 urwid 的新手,我在这里尝试了教程示例http://excess.org/urwid/docs/tutorial/
然而,虽然第一个确实可以正常工作,但大多数后来的似乎都不起作用。例如,尝试运行这个特定的:
import urwid
choices = u'Chapman Cleese Gilliam Idle Jones Palin'.split()
def menu(title, choices):
body = [urwid.Text(title), urwid.Divider()]
for c in choices:
button = urwid.Button(c)
urwid.connect_signal(button, 'click', item_chosen, c)
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def item_chosen(button, choice):
response = urwid.Text([u'You chose ', choice, u'\n'])
done = urwid.Button(u'Ok')
urwid.connect_signal(done, 'click', exit_program)
main.original_widget = urwid.Filler(urwid.Pile([response,
urwid.AttrMap(done, None, focus_map='reversed')]))
def exit_program(button):
raise urwid.ExitMainLoop()
main = urwid.Padding(menu(u'Pythons', choices), left=2, right=2)
top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
align='center', width=('relative', 60),
valign='middle', height=('relative', 60),
min_width=20, min_height=9)
urwid.MainLoop(top, palette=[('reversed', 'standout', '')]).run()
向我显示以下错误:
Traceback (most recent call last):
File "example.py", line 23, in <module>
main = urwid.Padding(menu(u'Pythons', choices), left=2, right=2)
File "example.py", line 11, in menu
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
AttributeError: 'module' object has no attribute 'SimpleFocusListWalker'
难道我做错了什么?如果它有任何帮助,我正在运行 Ubuntu 12.10 64 位。