FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

pythonnative/docs/api/appearance.md at v0.41.0 · pythonnative/pythonnative · GitHub

Repository navigation

Latest commit

 

History

History
42 lines (33 loc) · 1.2 KB

File metadata and controls

42 lines (33 loc) · 1.2 KB

Appearance

System color-scheme tracking with an optional app-level override. The screen host publishes the platform's light/dark setting into this module; [use_color_scheme][pythonnative.use_color_scheme] and [use_theme][pythonnative.use_theme] subscribe to it and re-render components when the effective scheme changes.

import pythonnative as pn


@pn.component
def SchemeAwareBadge():
    scheme = pn.use_color_scheme()  # "light" or "dark"
    theme = pn.use_theme()  # built-in theme for the scheme
    return pn.Text(
        f"Currently {scheme}",
        style={"color": theme.text_color},
    )

Force an appearance regardless of the system setting (for example from an in-app toggle), or return to following the system:

pn.appearance.set_color_scheme("dark")  # force dark
pn.appearance.set_color_scheme(None)  # follow the system again

::: pythonnative.appearance options: show_root_heading: false show_root_toc_entry: false members_order: source filters: ["!^_"]

Next steps

  • Theming with [use_theme][pythonnative.use_theme] and [ThemeContext][pythonnative.ThemeContext]: see Style and the Styling guide.

Back | FazBrowse Home | New Git URL