我使用urwid库遇到set_alarm问题。基本上,当你运行它并在Chapman上按Enter键时,你会得到以下错误。我不太了解urwid,它似乎缺乏文档,我试图寻找比较的例子,但我找不到任何。
import urwid
import pyfiglet
class data():
drpepper = pyfiglet.Figlet(font='doom')
choices = u'Chapman Cleese Gilliam Idle Jones Palin'.split()
def menu(self, title, choices):
body = [urwid.Text(title), urwid.Divider()]
for c in choices:
button = urwid.Button(c)
if c == "Chapman":
urwid.connect_signal(button, 'click', self.info, c)
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
def item_chosen(self, button, choice):
response = urwid.Text([u'You chose ', choice, u'\n'])
done = urwid.Button(u'Ok')
urwid.connect_signal(done, 'click', info)
main.original_widget = urwid.Filler(urwid.Pile([response, urwid.AttrMap(done, None, focus_map='reversed')]))
def info(self, button, choice):
response = urwid.Text(self.drpepper.renderText("text"), align="center")
response2 = urwid.Text("Test")
with open("/home/jt/works?.txt", "a+") as data:
data.write("THIS IS A TEST 2")
done = urwid.Button(u'Ok')
self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))
def exit_program(self, button):
raise urwid.ExitMainLoop()
def mainish(self):
main = urwid.Padding(self.menu(u'Pythons', self.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)
self.loop = urwid.MainLoop(top, palette=[('reversed', 'standout', '')])
self.loop.run()
start = data() start.mainish()
这是错误
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ < Traceback (most recent call last):
File "urwidtest.py", line 46, in <module>▒▒▒▒ < Cleese
crap.mainish()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ < Gilliam
File "urwidtest.py", line 42, in mainish▒▒▒▒▒ < Idle
self.loop.run()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ < Jones
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 278, in run
self._run()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 375, in _run
self.event_loop.run()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 678, in run
self._loop()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 715, in _loop
self._watch_files[fd]()▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 392, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 492, in parse_input
callback(processed, processed_codes)▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 399, in _update
self.process_input(keys)▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 499, in process_input
k = self._topmost_widget.keypress(self.screen_size, k)
File "/usr/local/lib/python3.4/dist-packages/urwid/container.py", line 592, in keypress
*self.calculate_padding_filler(size, True)), key)
File "/usr/local/lib/python3.4/dist-packages/urwid/decoration.py", line 621, in keypress
return self._original_widget.keypress(maxvals, key)
File "/usr/local/lib/python3.4/dist-packages/urwid/listbox.py", line 985, in keypress
key = focus_widget.keypress((maxcol,),key)▒
File "/usr/local/lib/python3.4/dist-packages/urwid/wimp.py", line 535, in keypress
self._emit('click')▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/widget.py", line 463, in _emit
signals.emit_signal(self, name, self, *args)
File "/usr/local/lib/python3.4/dist-packages/urwid/signals.py", line 264, in emit
result |= self._call_callback(callback, user_arg, user_args, args)
File "/usr/local/lib/python3.4/dist-packages/urwid/signals.py", line 294, in _call_callback▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
return bool(callback(*args_to_pass))▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "urwidtest.py", line 30, in info▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
File "/usr/local/lib/python3.4/dist-packages/urwid/container.py", line 1253, in __init__▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
if focus_item is None and w.selectable():▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
AttributeError: 'function' object has no attribute 'selectable'▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
答案 0 :(得分:0)
最后,经过无数个小时,你们几分钟就会发布一些东西。我喜欢python的支持社区(讽刺)...我喜欢人们声称它有一个很棒的支持社区,当我无法得到答案时。
好的,结束咆哮。这是为那些正在挣扎的人,因为没有其他人会帮助你。
Collection
在这里你看到main.original_widget清除屏幕并保留在一个位置。我无法解释为什么清楚,因为没有人会帮助。但是,我意识到你必须创建一个储备。
它需要文本编辑或其他东西。您无法调用窗口小部件中的函数。为什么?没有线索。询问Urwid社区是否可以获得单一回复。继续前进
通过创建保留,您可以创建一个var say&#34; self.x = urwid.Text(&#34;&#34;)&#34;没有任何内部我认为保留它。然后,通过创建say self.test.set_alarm_in(4)
来创建警报然后它将在4秒左右的时间内调用函数test()。所以你可以很容易地把self.x.set_text(&#34; hello world&#34;)放进去,它应该可以工作。