gpt4 book ai didi

set_alarm 的 Python Urwid 问题

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:21 26 4
gpt4 key购买 nike

我在使用库 urwid 时遇到 set_alarm 问题。基本上,当您运行它并在 Chapman 上按回车键时,您将收到以下错误。我对 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()

开始=数据()开始.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'▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

最佳答案

经过一千次组合,我终于明白了。知识?我随机地将黑客代码放在一起,直到它最终像暴力猜测一样起作用。

最后,在经历了无休止的几个小时之后,你们可能需要几分钟才能发布一些东西。我喜欢 python 的支持社区(讽刺)……我喜欢人们声称在我无法得到答案时它有一个很棒的支持社区。

好了,废话到此结束。这是为那些正在苦苦挣扎的人准备的,因为没有其他人可以帮助您。

self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))

在这里你看到 main.original_widget 清除屏幕并保留在一个地方。我无法解释清楚原因,因为没有人会提供帮助。但是,我意识到你必须创建一个储备。

它需要文本编辑或其他东西。您不能调用小部件内部的函数。为什么?没有线索。询问 Urwid 社区你是否能得到一个单一的回应。继续前进

通过创建一个保留,您创建了一个 var say "self.x = urwid.Text("")",其中没有任何内容,我认为它会保留它。之后,您通过创建 say self.test.set_alarm_in(4) 来创建警报

然后它将在 4 秒左右的时间内调用函数 test()。所以你可以轻松地放置 self.x.set_text("hello world") 它应该可以工作。

关于set_alarm 的 Python Urwid 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30963478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com