我正在尝试用文本项目制作一个 ListBox,其中每个项目的第一行是一个粗体的白色标题(前几个单词颜色为绿色),接下来的两行是灰色正文。
这是我目前拥有的:
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()
我的问题是如何在不改变“显示焦点”属性的行为的情况下向项目添加显示属性?即项目文本在被选中时仍应变为黑色并带有深青色背景,但在未选中时会以不同的方式进行风格化。