为什么这个简单的 "hello world" Urwid 代码会失败?
Why does this simple "hello world" Urwid code fail?
我有一个超级简单的程序,它使用 Urwid 作为基于文本的 UI:
import urwid
title = urwid.Text('Test')
pile = urwid.Pile([
title,
])
body = urwid.Frame(pile)
urwid.MainLoop(body).run()
但是当我 运行 它时,我得到这样的错误:
/home/user/anaconda3/envs/torch-env/bin/python /home/user/Work/market-maker/test.py
Traceback (most recent call last):
File "/home/user/Work/market-maker/test.py", line 97, in <module>
urwid.MainLoop(body).run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 287, in run
self._run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 385, in _run
self.event_loop.run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 790, in run
self._loop()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 818, in _loop
self._entering_idle()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 779, in _entering_idle
callback()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 574, in entering_idle
self.draw_screen()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 588, in draw_screen
canvas = self._topmost_widget.render(self.screen_size, focus=True)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/container.py", line 1089, in render
body = self.body.render((maxcol, maxrow-ftrim-htrim),
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/container.py", line 1565, in render
canv = w.render((maxcol, rows), focus=focus and item_focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 1001, in render
(maxcol,) = size
ValueError: too many values to unpack (expected 1)
Process finished with exit code 1
这是为什么?我错过了什么?
我设法通过将它放入 Filler 对象中使其工作
import urwid
title = urwid.Text('Test')
pile = urwid.Pile([
title
])
body = urwid.Filler(pile)
loop = urwid.MainLoop(body)
loop.run()
我有一个超级简单的程序,它使用 Urwid 作为基于文本的 UI:
import urwid
title = urwid.Text('Test')
pile = urwid.Pile([
title,
])
body = urwid.Frame(pile)
urwid.MainLoop(body).run()
但是当我 运行 它时,我得到这样的错误:
/home/user/anaconda3/envs/torch-env/bin/python /home/user/Work/market-maker/test.py
Traceback (most recent call last):
File "/home/user/Work/market-maker/test.py", line 97, in <module>
urwid.MainLoop(body).run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 287, in run
self._run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 385, in _run
self.event_loop.run()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 790, in run
self._loop()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 818, in _loop
self._entering_idle()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 779, in _entering_idle
callback()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 574, in entering_idle
self.draw_screen()
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/main_loop.py", line 588, in draw_screen
canvas = self._topmost_widget.render(self.screen_size, focus=True)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/container.py", line 1089, in render
body = self.body.render((maxcol, maxrow-ftrim-htrim),
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/container.py", line 1565, in render
canv = w.render((maxcol, rows), focus=focus and item_focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 145, in cached_render
canv = fn(self, size, focus=focus)
File "/home/user/anaconda3/envs/torch-env/lib/python3.8/site-packages/urwid/widget.py", line 1001, in render
(maxcol,) = size
ValueError: too many values to unpack (expected 1)
Process finished with exit code 1
这是为什么?我错过了什么?
我设法通过将它放入 Filler 对象中使其工作
import urwid
title = urwid.Text('Test')
pile = urwid.Pile([
title
])
body = urwid.Filler(pile)
loop = urwid.MainLoop(body)
loop.run()