Using Python (version: 3.10.6) and the Rich (version: 13.3.1) package, I'm attempting to display two tables side by side inside a panel, like this:
from rich.panel import Panel
from rich.table import Table
from rich.console import Console
console = Console()
table1 = Table()
table1.add_column("a")
table1.add_column("b")
table1.add_row("a", "b")
table1.add_row("a", "b")
table2 = Table()
table2.add_column("c")
table2.add_column("d")
table2.add_row("c", "d")
table2.add_row("c", "d")
panel = Panel.fit(
[table1, table2],
title="My Panel",
border_style="red",
title_align="left",
padding=(1, 2),
)
console.print(panel)
This code is producing the following Traceback:
File "/home/linux/ToolkitExtraction (copy 1)/table_in_panel.py", line 33, in <module>
console.print(panel)
File "/home/linux/.local/lib/python3.10/site-packages/rich/console.py", line 1694, in print
extend(render(renderable, render_options))
File "/home/linux/.local/lib/python3.10/site-packages/rich/console.py", line 1326, in render
for render_output in iter_render:
File "/home/linux/.local/lib/python3.10/site-packages/rich/panel.py", line 204, in __rich_console__
else console.measure(
File "/home/linux/.local/lib/python3.10/site-packages/rich/console.py", line 1278, in measure
measurement = Measurement.get(self, options or self.options, renderable)
File "/home/linux/.local/lib/python3.10/site-packages/rich/measure.py", line 109, in get
get_console_width(console, options)
File "/home/linux/.local/lib/python3.10/site-packages/rich/padding.py", line 132, in __rich_measure__
measure_min, measure_max = Measurement.get(console, options, self.renderable)
File "/home/linux/.local/lib/python3.10/site-packages/rich/measure.py", line 119, in get
raise errors.NotRenderableError(
rich.errors.NotRenderableError: Unable to get render width for [<rich.table.Table object at 0x7f562c1c2470>, <rich.table.Table object at 0x7f562c0411e0>]; a str, Segment, or object with __rich_console__ method is required
I tried inserting console.width = 150
prior to panel creation though this did not make any difference.