最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Urwid ListBox size to space available instead of constant - Stack Overflow

programmeradmin8浏览0评论

My program is split into 4 sections. One section is a constant-size section of various widgets, and the other 3 are list boxes.

If I set rows to 15, on this screen size, the program will crash. Also, if it is set to 5, then space is wasted that could be used to show more elements in list box 3.

What can I do to let 3 shrink and prevent crashes if the screen is not big enough so that 4 takes up > 50% of the vertical space? Also, if possible, how can I make 3 take up extra vertical space if it is available on a taller screen? Thank you.

What I've tried: explicitly setting weights, box/flow wrapper

import urwid

rows = 5

listbox1 = urwid.ListBox(urwid.SimpleFocusListWalker([]))
listbox2 = urwid.ListBox(urwid.SimpleFocusListWalker([]))
listbox3 = urwid.ListBox(urwid.SimpleFocusListWalker([]))

fixedSize = urwid.Pile([urwid.Text(f'Hello {x}') for x in range(rows)])

linebox1 = urwid.LineBox(listbox1, title="1")
linebox2 = urwid.LineBox(listbox2, title="2")
linebox3 = urwid.LineBox(listbox3, title="3")
linebox4 = urwid.LineBox(fixedSize, title="4")
print(linebox3)

layout = urwid.Columns([
    urwid.Pile([
        linebox1,
        linebox2
    ]),
    urwid.Pile([
        linebox3,
        linebox4
    ])
])

master = urwid.Frame(body=layout)

loop = urwid.MainLoop(master)
loop.run()
发布评论

评论列表(0)

  1. 暂无评论