我试图用文本项创建一个ListBox,其中每个项的第一行是粗体白色标题(前几个单词用绿色标记),接下来的两行是灰色正文。< / p>
这是我目前所拥有的:
class SelectableText(urwid.Text):
def selectable(self):
return True
def keypress(self, size, key):
return key
palette = [('reveal focus', 'black', 'dark cyan', 'standout')]
items = ["This part should be green and is the bold title!\nThese are the two lines of grey body text... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc facilisis at mi eu efficitur.", "This part should be green and is the bold title!\nThese are the two lines of grey body text... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc facilisis at mi eu efficitur."]
item_list = list(map(lambda item: urwid.AttrMap(SelectableText(item), None, "reveal focus"), items))
item_list_walker= urwid.SimpleListWalker(item_list)
listbox = urwid.ListBox(item_list_walker)
layout = urwid.Filler(listbox, valign="top", top=1, bottom=1)
main_loop = urwid.MainLoop(layout, palette)
main_loop.run()
我的问题是如何在不改变&#34;显示焦点的情况下向项目添加显示属性&#34;属性?即项目文本在选中时仍应为深蓝色背景,但如未选择则会以不同方式进行风格化。