rich.panel

class rich.panel.Panel(renderable: RenderableType, box: rich.box.Box = Box(...), *, title: Union[str, Text] = None, title_align: typing_extensions.Literal[left, center, right] = 'center', safe_box: Optional[bool] = None, expand: bool = True, style: Union[str, Style] = 'none', border_style: Union[str, Style] = 'none', width: Optional[int] = None, padding: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int, int]] = 0)[source]

A console renderable that draws a border around its contents.

Example

>>> console.print(Panel("Hello, World!"))
Parameters
  • renderable (RenderableType) – A console renderable object.

  • box (Box, optional) – A Box instance that defines the look of the border (see Box. Defaults to box.ROUNDED.

  • safe_box (bool, optional) – Disable box characters that don’t display on windows legacy terminal with raster fonts. Defaults to True.

  • expand (bool, optional) – If True the panel will stretch to fill the console width, otherwise it will be sized to fit the contents. Defaults to True.

  • style (str, optional) – The style of the panel (border and contents). Defaults to “none”.

  • border_style (str, optional) – The style of the border. Defaults to “none”.

  • width (Optional[int], optional) – Optional width of panel. Defaults to None to auto-detect.

  • padding (Optional[PaddingDimensions]) – Optional padding around renderable. Defaults to 0.

classmethod fit(renderable: RenderableType, box: rich.box.Box = Box(...), *, title: Union[str, Text] = None, title_align: typing_extensions.Literal[left, center, right] = 'center', safe_box: Optional[bool] = None, style: Union[str, Style] = 'none', border_style: Union[str, Style] = 'none', width: Optional[int] = None, padding: Union[int, Tuple[int], Tuple[int, int], Tuple[int, int, int, int]] = 0)[source]

An alternative constructor that sets expand=False.