Skip to main content

Button

A Fluent button: the standard button for most actions.

See also FilledButton for the main action, OutlinedButton, HyperlinkButton and IconButton.

Example:

fluent.Button("Save", on_click=lambda e: print("saved"))
fluent.Button("Save", disabled=True)
Button
Button

Inherits: LayoutControl

Properties

  • autofocus - Whether this button should be focused on initial display.
  • content - The button's label.

Events

  • on_blur - Called when this button loses focus.
  • on_click - Called when this button is clicked.
  • on_focus - Called when this button receives focus.
  • on_long_press - Called when this button is long-pressed.

Methods

  • focus - Requests focus for this button.

Example​

Fluent Button​

Sourceplay_arrowTry Online
import flet_fluent_ui as fluent

import flet as ft


def main(page: ft.Page):
page.title = "Fluent Button"

def handle_click(e: ft.Event[fluent.Button]):
status.value = "Changes discarded"

status = ft.Text("You have unsaved changes")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Row(
controls=[
fluent.Button("Discard changes", on_click=handle_click),
fluent.Button("Disabled", disabled=True),
],
),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
button
Discarding changes

Properties​

autofocusclass-attributeinstance-attribute​

autofocus: bool = False

Whether this button should be focused on initial display.

contentclass-attributeinstance-attribute​

content: StrOrControl | None = None

The button's label.

If a string is provided, it is wrapped in a Text control.

Events​

on_blurclass-attributeinstance-attribute​

on_blur: ControlEventHandler[Button] | None = None

Called when this button loses focus.

on_clickclass-attributeinstance-attribute​

on_click: ControlEventHandler[Button] | None = None

Called when this button is clicked.

on_focusclass-attributeinstance-attribute​

on_focus: ControlEventHandler[Button] | None = None

Called when this button receives focus.

on_long_pressclass-attributeinstance-attribute​

on_long_press: ControlEventHandler[Button] | None = None

Called when this button is long-pressed.

Methods​

focusasync​

focus()

Requests focus for this button.