如何更新 urwid 上的 Columns 小部件
how to update a Columns widget on urwid
我开始使用 urwid,我想做的一件简单的事情就是拥有两列并能够更新其中一列以显示不同的小部件
我尝试了以下代码,但我一直收到错误
urwid.container.ColumnsError: added content invalid <Filler box widget <Text flow widget 'other test'>>
我只想能够替代
from urwid import *
cols = Columns([Filler(Text('test')), Filler(Text('test'))])
loop = MainLoop(cols)
cols.contents[0] = Filler(Text('other test'))
# also tried .append just for trying, same result
loop.run()
我知道我可以用“.set_text()”更改文本小部件,但这不是我想要做的我想用其他小部件替换它。
我开始认为这显然不是应该的方式,但找不到任何相关信息。
提前致谢。
你很接近! :)
更新contents
列表时,需要提供一个元组,其中既包含小部件又包含选项对象(可以使用options()
方法构造),例如:
cols.contents[0] = (Filler(Text('other test')), cols.options())
我开始使用 urwid,我想做的一件简单的事情就是拥有两列并能够更新其中一列以显示不同的小部件
我尝试了以下代码,但我一直收到错误
urwid.container.ColumnsError: added content invalid <Filler box widget <Text flow widget 'other test'>>
我只想能够替代
from urwid import *
cols = Columns([Filler(Text('test')), Filler(Text('test'))])
loop = MainLoop(cols)
cols.contents[0] = Filler(Text('other test'))
# also tried .append just for trying, same result
loop.run()
我知道我可以用“.set_text()”更改文本小部件,但这不是我想要做的我想用其他小部件替换它。
我开始认为这显然不是应该的方式,但找不到任何相关信息。
提前致谢。
你很接近! :)
更新contents
列表时,需要提供一个元组,其中既包含小部件又包含选项对象(可以使用options()
方法构造),例如:
cols.contents[0] = (Filler(Text('other test')), cols.options())