如何让 urwid 给一个专栏比另一个专栏更多 space?
How to make urwid give more space to a Column than another?
我的 urwid 布局如下:
这个布局的代码是这样的:
import urwid
class DashboardUI:
orders_txt: urwid.widget.Text
def show_or_exit(self, key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
self.orders_txt.set_text(repr(key))
def show(self):
algo_view = urwid.Text(u"Main Content Goes Here")
algo_view_fill = urwid.Filler(algo_view, 'top')
algo_view_linebox = urwid.LineBox(algo_view_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'', rline=u'│', bline=u'', brcorner=u'│')
self.orders_txt = urwid.Text(u"Orders\norder2\norder3")
orders_fill = urwid.Filler(self.orders_txt, 'bottom')
orders_linebox = urwid.LineBox(orders_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')
counter_txt = urwid.Text(u"Counter 1\nCounter 2\nCounter 3")
counters_fill = urwid.Filler(counter_txt, 'top')
counters_linebox = urwid.LineBox(counters_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')
resources_txt = urwid.Text(u"Resources 1\nResources 2\nResources 3")
resources_fill = urwid.Filler(resources_txt, 'top')
resources_linebox = urwid.LineBox(resources_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'', rline=u'', bline=u'', brcorner=u'')
right_pile = urwid.Pile([orders_linebox, counters_linebox, resources_linebox])
layout = urwid.Columns([algo_view_linebox, right_pile], dividechars=0)
loop = urwid.MainLoop(layout, unhandled_input=self.show_or_exit)
loop.run()
我希望左列占可用字符的 75% space,右列占 25%(理想情况下宽度最多为 100 个字符)。
我怎样才能让它具有这种改变的行为?
找到了。
必须在添加列的同时指定它们的权重,如下所示:
layout = urwid.Columns([('weight', 3, algo_view_linebox), right_pile])
对于右侧小部件,无需指定权重,默认为1。
我的 urwid 布局如下:
这个布局的代码是这样的:
import urwid
class DashboardUI:
orders_txt: urwid.widget.Text
def show_or_exit(self, key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
self.orders_txt.set_text(repr(key))
def show(self):
algo_view = urwid.Text(u"Main Content Goes Here")
algo_view_fill = urwid.Filler(algo_view, 'top')
algo_view_linebox = urwid.LineBox(algo_view_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'', rline=u'│', bline=u'', brcorner=u'│')
self.orders_txt = urwid.Text(u"Orders\norder2\norder3")
orders_fill = urwid.Filler(self.orders_txt, 'bottom')
orders_linebox = urwid.LineBox(orders_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')
counter_txt = urwid.Text(u"Counter 1\nCounter 2\nCounter 3")
counters_fill = urwid.Filler(counter_txt, 'top')
counters_linebox = urwid.LineBox(counters_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')
resources_txt = urwid.Text(u"Resources 1\nResources 2\nResources 3")
resources_fill = urwid.Filler(resources_txt, 'top')
resources_linebox = urwid.LineBox(resources_fill,
tlcorner=u'', tline=u'', lline=u'', trcorner=u'',
blcorner=u'', rline=u'', bline=u'', brcorner=u'')
right_pile = urwid.Pile([orders_linebox, counters_linebox, resources_linebox])
layout = urwid.Columns([algo_view_linebox, right_pile], dividechars=0)
loop = urwid.MainLoop(layout, unhandled_input=self.show_or_exit)
loop.run()
我希望左列占可用字符的 75% space,右列占 25%(理想情况下宽度最多为 100 个字符)。
我怎样才能让它具有这种改变的行为?
找到了。
必须在添加列的同时指定它们的权重,如下所示:
layout = urwid.Columns([('weight', 3, algo_view_linebox), right_pile])
对于右侧小部件,无需指定权重,默认为1。