Python Flet Tutorial: Minimize Code Clutter In Flet Apps

preview_player
Показать описание
Here's a short but very useful Python tutorial on how to use Python dictionary to separate widget styling in order to minimize code cluttering and increase code readability. Plus, a bonus at the end shoving how to implement in-line conditionals inside dictionaries to toggle easily between light and dark mode.

Channel GitHub:

Soundtrack credits:

(00:00-2:32)
Artificial.Music - Faithful Mission" is under a Creative Commons (CC BY 3.0) license.
/ smarttoaster

(2:33-6:13)
"Sappheiros - Dawn" está bajo licencia Creative Commons license (CC BY 3.0)

(6:14-9:08)
"KaizanBlu - Daydream" is under a Creative Commons (CC BY-NC-SA 3.0) license.
/ kaizanblu

(9:09-9:16)
"Hayden Folker - Dreams" is under a Creative Commons (CC BY 3.0) license.

All the music is promoted by BreakingCopyright.
Рекомендации по теме
Комментарии
Автор

Omg how so smooth tutorial, thanks a million for the incredibely useful content

levelup
Автор

Thank you. In your other video you use **main_style in another class rather than in def main. How to use the condition then since there is no theme_mode ?

gangs
Автор

Hi, why dont work for me?

from typing import Any
import flet as ft


def box_style(theme: ft.Page.theme_mode) -> dict[str, Any]:
# having access to the theme property allows us to use
print(theme)
return {
"width": 100,
"height": 100,
"bgcolor": "teal" if theme == "dark" else "pink",
"border_radius": 6,
"border": ft.border.all(2, "white") if theme == "dark" else ft.border.all(2, "black")
}


def main(page: ft.Page) -> None:
page.horizontal_alignment = "center"
page.vertical_alignment = "center"
page.theme_mode = "white"

def dropdown_changed(e):
page.theme_mode = e.data
print(e.data)
page.update()

drop = ft.Dropdown(on_change=dropdown_changed,
options=[
ft.dropdown.Option("dark"),
ft.dropdown.Option("white")])

page.add(drop,
page.update()


ft.app(target=main)

dppic
Автор

what if if want to change some property of new object... say bg_color="pink" for new container

praveenhamal
Автор

Hola, en el momento estoy intentando hacer que unas imágenes dentro de un contenedor cambien de tamaño según como cambie de tamaño la pantalla, pero no lo he logrado. Te agradecería pudieras ayudarme

Nicpesca