Skip to content

Banner

Examples#

Live example

Basic example#

import flet as ft


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    def handle_banner_close(e: ft.Event[ft.TextButton]):
        page.pop_dialog()
        page.add(ft.Text("Action clicked: " + e.control.content))

    action_button_style = ft.ButtonStyle(color=ft.Colors.BLUE)
    banner = ft.Banner(
        bgcolor=ft.Colors.AMBER_100,
        leading=ft.Icon(ft.Icons.WARNING_AMBER_ROUNDED, color=ft.Colors.AMBER, size=40),
        content=ft.Text(
            value="Oops, there were some errors while trying to delete the file. What would you like to do?",
            color=ft.Colors.BLACK,
        ),
        actions=[
            ft.TextButton(
                content="Retry",
                style=action_button_style,
                on_click=handle_banner_close,
            ),
            ft.TextButton(
                content="Ignore",
                style=action_button_style,
                on_click=handle_banner_close,
            ),
            ft.TextButton(
                content="Cancel",
                style=action_button_style,
                on_click=handle_banner_close,
            ),
        ],
    )

    page.add(
        ft.ElevatedButton("Show Banner", on_click=lambda e: page.show_dialog(banner))
    )


ft.run(main)

basic

Banner #

Bases: DialogControl

A banner displays an important, succinct message, and provides actions for users to address (or dismiss the banner). A user action is required for it to be dismissed.

Banners are displayed at the top of the screen, below a top app bar. They are persistent and non-modal, allowing the user to either ignore them or interact with them at any time.

RAISES DESCRIPTION
AssertionError

if content is not visible.

AssertionError

if elevation is negative.

AssertionError

if actions does not contain at least one visible action Control.

actions #

actions: list[Control]

The set of actions that are displayed at the bottom or trailing side of this banner.

Typically this is a list of TextButton controls.

adaptive #

adaptive: bool | None = None

Enables platform-specific rendering or inheritance of adaptiveness from parent controls.

badge #

badge: BadgeValue | None = None

A badge to show on top of this control.

bgcolor #

bgcolor: ColorValue | None = None

The color of the surface of this banner.

col #

col: ResponsiveNumber = 12

If a parent of this control is a ResponsiveRow, this property is used to determine how many virtual columns of a screen this control will span.

Can be a number or a dictionary configured to have a different value for specific breakpoints, for example col={"sm": 6}.

This control spans the 12 virtual columns by default.

Dimensions
Breakpoint Dimension
xs <576px
sm ≥576px
md ≥768px
lg ≥992px
xl ≥1200px
xxl ≥1400px

content #

content: StrOrControl

The content of this banner.

Typically a Text control.

content_padding #

content_padding: PaddingValue | None = None

The amount of space by which to inset the content.

If the actions are below the content, this defaults to Padding.only(left=16.0, top=24.0, right=16.0, bottom=4.0).

If the actions are trailing the content, this defaults to Padding.only(left=16.0, top=2.0).

content_text_style #

content_text_style: TextStyle | None = None

The style to be used for the Text controls in the content.

data #

data: Any = skip_field()

Arbitrary data of any type.

disabled #

disabled: bool = False

Every control has disabled property which is False by default - control and all its children are enabled.

Note

The value of this property will be propagated down to all children controls recursively.

Example

For example, if you have a form with multiple entry controls you can disable them all together by disabling container:

ft.Column(
    disabled = True,
    controls=[
        ft.TextField(),
        ft.TextField()
    ]
)

divider_color #

divider_color: ColorValue | None = None

The color of the divider.

elevation #

elevation: Number | None = None

The elevation of this banner.

expand #

expand: bool | int | None = None

Specifies whether/how this control should expand to fill available space in its parent layout.

More information here.

Note

Has effect only if the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

expand_loose #

expand_loose: bool = False

Allows the control to expand along the main axis if space is available, but does not require it to fill all available space.

More information here.

Note

If expand_loose is True, it will have effect only if:

  • expand is not None and
  • the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

force_actions_below #

force_actions_below: bool = False

An override to force the actions to be below the content regardless of how many there are.

If this is True, the actions will be placed below the content. If this is False, the actions will be placed on the trailing side of the content if actions length is 1 and below the content if greater than 1.

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

leading #

leading: IconValueOrControl | None = None

The leading Control of this banner.

Typically an Icon control.

leading_padding #

leading_padding: PaddingValue | None = None

The amount of space by which to inset the leading control.

Defaults to BannerTheme.leading_padding, or if that is None, falls back to Padding.only(end=16).

margin #

margin: MarginValue | None = None

The amount of space surrounding this banner.

min_action_bar_height #

min_action_bar_height: Number = 52.0

The optional minimum action bar height.

on_dismiss #

on_dismiss: ControlEventHandler[DialogControl] | None = None

Called when dialog is dismissed.

on_visible #

on_visible: ControlEventHandler[Banner] | None = None

Called when this banner is shown or made visible for the first time.

opacity #

opacity: Number = 1.0

Defines the transparency of the control.

Value ranges from 0.0 (completely transparent) to 1.0 (completely opaque without any transparency).

open #

open: bool = False

Set to True to display this dialog.

page #

page: Page | PageView | None

The page (of type Page or PageView) to which this control belongs to.

parent #

parent: BaseControl | None

The direct ancestor(parent) of this control.

It defaults to None and will only have a value when this control is mounted (added to the page tree).

The Page control (which is the root of the tree) is an exception - it always has parent=None.

rtl #

rtl: bool = False

Whether the text direction of the control should be right-to-left (RTL).

shadow_color #

shadow_color: ColorValue | None = None

The color of the shadow below this banner.

surface_tint_color #

surface_tint_color: ColorValue | None = None

The color used as an overlay on bgcolor to indicate elevation.

tooltip #

tooltip: TooltipValue | None = None

The tooltip ot show when this control is hovered over.

visible #

visible: bool = True

Every control has visible property which is True by default - control is rendered on the page. Setting visible to False completely prevents control (and all its children if any) from rendering on a page canvas. Hidden controls cannot be focused or selected with a keyboard or mouse and they do not emit any events.

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

clean #

clean() -> None

did_mount #

did_mount()

init #

init()

is_isolated #

is_isolated()

update #

update() -> None

will_unmount #

will_unmount()