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

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

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()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744384613a4571600.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信