跳转至

maliang.theme

字数 11 个   阅读时间不到 1 分钟   访问量

源代码:maliang/theme/__init__.py

A subpackage that provides theme-related features.

Listen to the system’s theme and respond accordingly, modify the style of the window, and more.

模块:

函数:

set_color_mode

set_color_mode(mode: typing.Literal['system', 'dark', 'light'] = 'system') -> None

Set the color mode of the program

  • mode: it can be "light", "dark", and "system"

TIP:

"system" is the following system

get_color_mode

get_color_mode() -> typing.Literal['dark', 'light']

Get the color mode of the program.

register_event

register_event(func: collections.abc.Callable[..., typing.Any], *args: typing.Any) -> None

When the system accent color changes, the registered function will be called, and the parameter is a boolean value indicating whether it is currently a dark theme.

  • func: callback function
  • args: extra arguments

remove_event

remove_event(func: collections.abc.Callable[..., typing.Any]) -> None

Remove a registered function.

  • func: callback function

apply_file_dnd

apply_file_dnd(window: tkinter.Tk, *, command: collections.abc.Callable[[str], typing.Any]) -> None

Apply file drag and drop in a widget.

  • window: the window which being customized
  • command: callback function, accept a parameter that represents the path of the file

This function is only works on Windows OS!

apply_theme

apply_theme(
    window: tkinter.Tk,
    *,
    theme: typing.Literal[
        "mica",
        "acrylic",
        "acrylic2",
        "aero",
        "transparent",
        "optimised",
        "win7",
        "inverse",
        "native",
        "popup",
        "dark",
        "normal",
    ]
) -> None

Apply some Windows themes to the window.

  • window: the window which being customized
  • theme: different themes for windows

This function is only works on Windows OS! And some parameters are useless on Windows 7/10!

customize_window

customize_window(
    window: tkinter.Tk,
    *,
    border_color: str | None = None,
    header_color: str | None = None,
    title_color: str | None = None,
    hide_title_bar: bool | None = None,
    hide_button: typing.Literal["all", "maxmin", "none"] | None = None,
    disable_minimize_button: bool | None = None,
    disable_maximize_button: bool | None = None,
    border_type: typing.Literal["rectangular", "smallround", "round"] | None = None
) -> None

Customize the relevant properties of the window

  • window: the window which being customized
  • border_color: border color of the window
  • header_color: header color of the window
  • title_color: title color of the window
  • hide_title_bar: Wether hide the whole title bar
  • hide_button: Wether hide part of buttons on title bar
  • disable_minimize_button: Wether disable minimize button
  • disable_maximize_button: Wether disable maximize button
  • border_type: border type of the window

This function is only works on Windows OS! And some parameters are useless on Windows 7/10!