跳转至

maliang

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

源代码:maliang/__init__.py

A lightweight UI framework based on tkinter with all UI drawn in Canvas.

If you ❤️ this package, please leave your ⭐ to us, thank you very much!

Stars Forks Watchers

模块:

  • animation

    A subpackage that provides animation-related features.

  • color

    A subpackage that provides color-related features.

  • core

    The core code, you can see the general framework here.

  • media

    Extension package of maliang to play media files

  • mpl

    Extension package of maliang for matplotlib

  • standard

    All standard things.

  • theme

    A subpackage that provides theme-related features.

  • three

    Extension package of maliang for simple 3D drawings

  • toolbox

    Some practical tools

类:

  • Env

    Configurations for default environment values.

  • Font

    Configurations for default font.

  • Constant

    All Constants.

  • Tk

    Main window.

  • Toplevel

    Toplevel window.

  • Canvas

    Main contrainer: Canvas.

  • TkMessage

    Message pop-up

  • TkColorChooser

    Color chooser pop-up

  • TkFontChooser

    Font chooser pop-up

  • Text

    Text widget, generally used to display plain text

  • Image

    Image widget, generally used to display normal still image

  • Label

    Label widget, which is generally used to display key information

  • Button

    Button widget, typically used to trigger a function

  • Switch

    Switch widget, typically used to control the turning of a function on and off

  • InputBox

    Input box widget, generally used to enter certain information on a single line

  • CheckBox

    Checkbox button widget, generally used to check some options

  • ToggleButton

    A button that can display information and switch statuses

  • RadioBox

    Radio button widget, generally used to select one of several options

  • ProgressBar

    Progress bar widget, typically used to show the progress of an event

  • UnderlineButton

    Underline button, generally used to display web links

  • HighlightButton

    Highlight button, no outline, which added a highlight effect

  • IconButton

    A button with an icon on the left side

  • Slider

    A slider for visually resizing values

  • SegmentedButton

    A segmented button that can be used to toggle between multiple states

  • SpinBox

    A widget that makes it easy to enter numeric type data

  • OptionButton

    A button that has many options to choose

  • ComboBox

    An input box that can provide several options

  • Spinner

    Spinners visually communicate that something is processing

  • Tooltip

    A tooltip that can display additional information

  • PhotoImage

    Pillow version of tkinter.PhotoImage.

函数:

  • reset

    Reset all configuration options.

Env

Configurations for default environment values.

方法:

reset classmethod

reset() -> None

Reset all configuration options.

get_default_system staticmethod

get_default_system() -> str

Get the system of environment.

Font

Configurations for default font.

方法:

reset classmethod

reset() -> None

Reset all configuration options.

get_default_family staticmethod

get_default_family() -> str

Get the default font family.

Constant

All Constants.

属性:

GOLDEN_RATIO class-attribute instance-attribute

GOLDEN_RATIO: typing.Final[float] = math.sqrt(5) - 1 / 2

The golden ratio, which is needed to automatically calculate the color of widget on "disabled" state. It is READ-ONLY.

PREDEFINED_EVENTS class-attribute instance-attribute

PREDEFINED_EVENTS: typing.Final[tuple[str, ...]] = (
    "<KeyPress>",
    "<KeyRelease>",
    "<Button-1>",
    "<Button-2>",
    "<Button-3>",
    "<Button-4>",
    "<Button-5>",
    "<ButtonRelease-1>",
    "<ButtonRelease-2>",
    "<ButtonRelease-3>",
    "<MouseWheel>",
    "<Motion>",
    "<B1-Motion>",
    "<B2-Motion>",
    "<B3-Motion>",
    "<Configure>",
)

Predefined events that can be used directly without registration. It is READ-ONLY.

PREDEFINED_VIRTUAL_EVENTS class-attribute instance-attribute

PREDEFINED_VIRTUAL_EVENTS: typing.Final[tuple[str, ...]] = (
    "<<Copy>>",
    "<<Paste>>",
    "<<Cut>>",
    "<<SelectAll>>",
    "<<Redo>>",
    "<<Undo>>",
)

Predefined virtual events that can be used directly without registration. It is READ-ONLY.

Tk

Tk(
    size: tuple[int, int] = (1280, 720),
    position: tuple[int, int] | None = None,
    *,
    title: str | None = None,
    icon: str | enhanced.PhotoImage | None = None,
    **kwargs
)

Bases: tkinter.Tk, Misc

Main window.

In general, there is only one main window. But after destroying it, another one can be created.

  • size: size of the window
  • position: position of the window, based on the upper left (nw) corner. And negative numbers are based on the bottom right (se) corner.
  • title: title of the window, default value is "tk"
  • icon: icon of the window, default value is the icon of tk
  • **kwargs: compatible with other parameters of class tkinter.Tk

方法:

  • theme

    Change the color theme of the window

  • geometry

    Change the size and position of the window and return the current

  • center

    Center the container

  • icon

    Set the icon of the window.

  • alpha

    Set or get the transparency of the window

  • topmost

    Set or get whether the window is pinned or not

  • fullscreen

    Set or get whether the window is full-screen.

  • toolwindow

    Set or get whether the window is tool-window.

  • transparentcolor

    Set or get the penetration color of the window.

  • modified

    Set or get whether the window is modified.

  • transparent

    Set or get whether the window is transparent.

  • destroy

    Destroy this and all descendants widgets.

  • at_exit

    Set a function that will be called when the window is closed.

属性:

ratios cached property

ratios: tuple[float, float]

Return the aspect zoom ratio of the container.

theme

theme(
    value: typing.Literal["light", "dark"],
    *,
    include_children: bool = True,
    include_canvases: bool = True
) -> None

Change the color theme of the window

  • value: theme name
  • include_children: wether include its children, like Toplevel
  • include_canvases: wether include its canvases

geometry

geometry(
    *, size: tuple[int, int] | None = None, position: tuple[int, int] | None = None
) -> tuple[int, int, int, int] | None

Change the size and position of the window and return the current size and position of the window.

  • size: the size of the window, if it is None, does not change anything
  • position: the position of the window, if it is None, does not change anything

If you want to use tkinter.Tk.geometry, please use tkinter.Tk.wm_geometry instead.

center

center(*, refer: tkinter.Misc | None = None) -> None

Center the container

refer: The area of the reference widget, if it is None, means that the reference area is the entire screen.

icon

icon(value: str | enhanced.PhotoImage) -> None

Set the icon of the window.

  • value: the icon

alpha

alpha(value: float | None = None) -> float | None

Set or get the transparency of the window

  • value: the transparency of the window, range is 0~1

topmost

topmost(value: bool | None = True) -> bool | None

Set or get whether the window is pinned or not

  • value: indicate whether the window is topmost

fullscreen

fullscreen(value: bool | None = True) -> bool | None

Set or get whether the window is full-screen.

  • value: indicate whether the window is full-screen

The method should be called at the end of the code, or after some time after the program has started.

toolwindow

toolwindow(value: bool | None = True) -> bool | None

Set or get whether the window is tool-window.

  • value: indicate whether the window is tool-window

This method only works on Windows!

transparentcolor

transparentcolor(value: str | None = None) -> str | None

Set or get the penetration color of the window.

  • value: the penetration color of the window

This method only works on Windows!

modified

modified(value: bool | None = None) -> bool | None

Set or get whether the window is modified.

  • value: indicate whether the window is modified

This method only works on macOS!

transparent

transparent(value: bool | None = None) -> bool | None

Set or get whether the window is transparent.

  • value: indicate whether the window is transparent

This method only works on macOS!

destroy

destroy() -> None

Destroy this and all descendants widgets.

at_exit

at_exit(command: collections.abc.Callable[[], typing.Any], *, ensure_destroy: bool = True) -> None

Set a function that will be called when the window is closed.

  • command: the function that was called
  • ensure_destroy: whether the window is guaranteed to be closed

Toplevel

Toplevel(
    master: Tk | Toplevel | None = None,
    size: tuple[int, int] = (960, 540),
    position: tuple[int, int] | None = None,
    *,
    title: str | None = None,
    icon: str | enhanced.PhotoImage | None = None,
    grab: bool = False,
    focus: bool = True,
    **kwargs
)

Bases: tkinter.Toplevel, Tk, Misc

Toplevel window.

It can be used as a pop-up window, or it can be customized to put anything you want to show.

  • master: parent widget
  • size: size of the window, default value is 960x540(px)
  • position: position of the window, default value indicates random
  • title: title of window, default is the same as title of master
  • icon: icon of the window, default is the same as title of master
  • grab: set grab for this window
  • focus: whether direct input focus to this window
  • **kwargs: compatible with other parameters of class tkinter.Toplevel

方法:

  • destroy

    Destroy this and all descendants widgets.

destroy

destroy() -> None

Destroy this and all descendants widgets.

Canvas

Canvas(
    master: Tk | Toplevel | Canvas | None = None,
    *,
    expand: typing.Literal["", "x", "y", "xy"] = "xy",
    auto_zoom: bool = False,
    keep_ratio: typing.Literal["min", "max"] | None = None,
    free_anchor: bool = False,
    auto_update: bool | None = None,
    zoom_all_items: bool = False,
    **kwargs
)

Bases: tkinter.Canvas, Misc

Main contrainer: Canvas.

The parent widget of all virtual widgets is Canvas.

  • master: parent widget
  • expand: the mode of expand, x is horizontal, and y is vertical
  • auto_zoom: whether or not to scale its items automatically
  • keep_ratio: the mode of aspect ratio, min follows the minimum value, max follows the maximum value
  • free_anchor: whether the anchor point is free-floating
  • auto_update: whether the theme manager update it automatically
  • zoom_all_items: (Experimental) whether or not to scale its all items
  • kwargs: compatible with other parameters of class tkinter.Canvas

方法:

  • theme

    Change the color theme of the Canvas and its items

  • zoom

    Resize and position the Canvas based on the relevant parameters.

  • destroy

    Destroy this and all descendants widgets.

  • clear

    Clear all things in the Canvas.

  • create_text

    Create text with coordinates x, y.

  • on_motion

    Events to move the mouse

  • on_click

    Events to active the mouse

  • on_release

    Events to release the mouse

  • on_wheel

    Events to scroll the mouse wheel

  • on_key_press

    Events for typing

  • on_key_release

    Events for typing

  • register_event

    Register a event to process.

属性:

ratios cached property

ratios: tuple[float, float]

Return the aspect zoom ratio of the widget.

theme

theme(value: typing.Literal['light', 'dark']) -> None

Change the color theme of the Canvas and its items

  • value: theme name

zoom

zoom() -> None

Resize and position the Canvas based on the relevant parameters.

This method only works for Canvas with Place layout.

destroy

destroy() -> None

Destroy this and all descendants widgets.

clear

clear() -> None

Clear all things in the Canvas.

create_text

create_text(x: float, y: float, /, *args, **kwargs) -> int

Create text with coordinates x, y.

on_motion

on_motion(event: tkinter.Event, name: str) -> None

Events to move the mouse

on_click

on_click(event: tkinter.Event, name: str) -> None

Events to active the mouse

on_release

on_release(event: tkinter.Event, name: str) -> None

Events to release the mouse

on_wheel

on_wheel(event: tkinter.Event, type_: bool | None) -> None

Events to scroll the mouse wheel

on_key_press

on_key_press(event: tkinter.Event) -> None

Events for typing

on_key_release

on_key_release(event: tkinter.Event) -> None

Events for typing

register_event

register_event(name: str, *, add: bool | typing.Literal['', '+'] | None = None) -> str

Register a event to process.

  • name: event name, such as “
  • add: whether it is an attached call

In general, you don’t need to call this method, but when the event to be bound is not in the predefined event, you need to manually call the method once.

TkMessage

TkMessage(
    message: str | None = None,
    detail: str | None = None,
    *,
    title: str | None = None,
    icon: typing.Literal["error", "info", "question", "warning"] = "info",
    option: typing.Literal[
        "abortretryignore", "ok", "okcancel", "retrycancel", "yesno", "yesnocancel"
    ] = "ok",
    default: typing.Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"] | None = None,
    master: tkinter.Tk | None = None,
    command: (
        collections.abc.Callable[
            [typing.Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"]], typing.Any
        ]
        | None
    ) = None
)

Message pop-up

  • message: message
  • detail: detail message
  • title: title of the window
  • icon: icon
  • option: type of the message pop-up
  • default: button where the focus is, default is the leftmost one
  • master: parent widget of the window
  • command: callback function

TkColorChooser

TkColorChooser(
    *,
    title: str | None = None,
    color: str | None = None,
    master: tkinter.Tk | None = None,
    command: collections.abc.Callable[[str], typing.Any] | None = None
)

Color chooser pop-up

  • title: title of the window
  • color: default color
  • master: parent widget of the window
  • command: callback function

TkFontChooser

TkFontChooser(
    *,
    title: str | None = None,
    font: str | None = None,
    master: tkinter.Tk | None = None,
    command: collections.abc.Callable[[str], typing.Any] | None = None
)

Font chooser pop-up

  • title: title of the window
  • font: default font
  • master: parent widget of the window
  • command: callback function

Text

Text(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Text widget, generally used to display plain text

  • master: parent canvas
  • position: position of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the text of the widget

  • set

    Set the text of the widget

get

get() -> str

Get the text of the widget

set

set(text: str) -> None

Set the text of the widget

Image

Image(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Image widget, generally used to display normal still image

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the image of the widget

  • set

    Set the image of the widget

get

Get the image of the widget

set

set(image: enhanced.PhotoImage | None) -> None

Set the image of the widget

Label

Label(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Label widget, which is generally used to display key information

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the text of the widget

  • set

    Set the text of the widget

get

get() -> str

Get the text of the widget

set

set(text: str) -> None

Set the text of the widget

Button

Button(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    command: collections.abc.Callable | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Button widget, typically used to trigger a function

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the text of the widget

  • set

    Set the text of the widget

get

get() -> str

Get the text of the widget

set

set(text: str) -> None

Set the text of the widget

Switch

Switch(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    length: int = 60,
    *,
    default: bool | None = None,
    command: collections.abc.Callable[[bool], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Switch widget, typically used to control the turning of a function on and off

  • master: parent canvas
  • position: position of the widget
  • length: length of the widget
  • default: default value of the widget
  • command: a function that is triggered when the switch is changed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the state of the switch

  • set

    Set the state of the switch

get

get() -> bool

Get the state of the switch

set

set(value: bool, *, callback: bool = False) -> None

Set the state of the switch

InputBox

InputBox(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    align: typing.Literal["left", "right", "center"] = "left",
    placeholder: str = "",
    show: str | None = None,
    ignore: tuple[str, ...] = ("\n", "\r"),
    limit: int = math.inf,
    limit_width: int = 0,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Input box widget, generally used to enter certain information on a single line

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • align: align mode of the text
  • show: display a value that obscures the original content
  • ignore: ignore the input of some characters
  • placeholder: a placeholder for the prompt
  • limit: limit on the number of characters
  • limit_width: limit on the width of characters
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the value of the Entry

  • set

    Set the text value of the Entry

  • insert

    Insert

  • append

    Append text to Entry

  • remove

    Remove

  • pop

    Delete a specified amount of text

  • clear

    Clear the text value of the Entry

get

get() -> str

Get the value of the Entry

set

set(value: str) -> bool

Set the text value of the Entry

insert

insert(index: int, value: str) -> bool

Insert

append

append(value: str) -> bool

Append text to Entry

remove

remove(start: int, end: int | None = None) -> int

Remove

pop

pop(index: int = -1) -> str

Delete a specified amount of text

clear

clear() -> None

Clear the text value of the Entry

CheckBox

CheckBox(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    length: int = 30,
    *,
    default: bool | None = None,
    command: collections.abc.Callable[[bool], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Checkbox button widget, generally used to check some options

  • master: parent canvas
  • position: position of the widget
  • length: length of the widget
  • default: default state of the widget
  • command: a function that is triggered when the state of check button is on
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the state of the check button

  • set

    Set the state of the check button

get

get() -> bool

Get the state of the check button

set

set(value: bool, *, callback: bool = False) -> None

Set the state of the check button

ToggleButton

ToggleButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    default: bool | None = None,
    command: collections.abc.Callable[[bool], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A button that can display information and switch statuses

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • default: default state of the widget
  • command: a function that is triggered when the state of check button is on
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the state of the check button

  • set

    Set the state of the switch

get

get() -> bool

Get the state of the check button

set

set(value: bool, *, callback: bool = False) -> None

Set the state of the switch

RadioBox

RadioBox(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    length: int = 30,
    *,
    default: bool | None = None,
    command: collections.abc.Callable[[int], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Radio button widget, generally used to select one of several options

  • master: parent canvas
  • position: position of the widget
  • length: length of the widget
  • default: default state of the widget
  • command: a function that is triggered when the state of radio button is on
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the state of the radio button

  • set

    Set the state of the radio button

  • group

    Combine other radio boxes.

get

get() -> bool

Get the state of the radio button

set

set(value: bool, *, callback: bool = False) -> None

Set the state of the radio button

group

group(*radio_boxes: RadioBox) -> None

Combine other radio boxes.

  • radio_boxes: other radio boxes

ProgressBar

ProgressBar(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] = (400, 20),
    *,
    default: float | None = None,
    command: collections.abc.Callable[[float], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Progress bar widget, typically used to show the progress of an event

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • default: default value of the widget
  • command: a function that is triggered when the progress of progress bar is 100%
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the progress of the progress bar

  • set

    Set the progress of the progress bar

get

get() -> float

Get the progress of the progress bar

set

set(value: float, *, callback: bool = False) -> None

Set the progress of the progress bar

UnderlineButton

UnderlineButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    command: collections.abc.Callable | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool = False,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Underline button, generally used to display web links

  • master: parent canvas
  • position: position of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • command: a function that is triggered when the underline button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

HighlightButton

HighlightButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    command: collections.abc.Callable | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Highlight button, no outline, which added a highlight effect

  • master: parent canvas
  • position: position of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • command: a function that is triggered when the hightlight button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

IconButton

IconButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: str = "",
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    command: collections.abc.Callable | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A button with an icon on the left side

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the text of the widget

  • set

    Set the text of the widget

get

get() -> str

Get the text of the widget

set

set(text: str) -> None

Set the text of the widget

Slider

Slider(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] = (400, 30),
    *,
    default: float | None = None,
    command: collections.abc.Callable[[float], typing.Any] | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A slider for visually resizing values

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • default: default value of the widget
  • command: a function that is triggered when the button is pressed
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the value of the slider

  • set

    Set the value of the slider

get

get() -> float

Get the value of the slider

set

set(value: float, *, callback: bool = False) -> None

Set the value of the slider

SegmentedButton

SegmentedButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    sizes: tuple[tuple[int, int], ...] = (),
    *,
    text: tuple[str, ...] = (),
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    default: int | None = None,
    command: collections.abc.Callable[[int | None], typing.Any] | None = None,
    image: tuple[enhanced.PhotoImage | None, ...] = (),
    layout: typing.Literal["horizontal", "vertical"] = "horizontal",
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A segmented button that can be used to toggle between multiple states

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • default: default value of the widget
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • layout: layout mode of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the index of the child toggle button with a value of True. If not, None is

  • set

    Activate the child toggle button for the specified index

get

get() -> int | None

Get the index of the child toggle button with a value of True. If not, None is returned.

set

set(value: int | None, *, callback: bool = False) -> None

Activate the child toggle button for the specified index

SpinBox

SpinBox(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    format_spec: str = "d",
    step: int = 1,
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    align: typing.Literal["left", "right", "center"] = "left",
    placeholder: str = "",
    show: str | None = None,
    limit: int = math.inf,
    default: str | None = None,
    command: collections.abc.Callable[[bool], typing.Any] | None = None,
    image: enhanced.PhotoImage | None = None,
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A widget that makes it easy to enter numeric type data

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • format_spec: format of value
  • step: value of each change
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • align: align mode of the text
  • show: display a value that obscures the original content
  • placeholder: a placeholder for the prompt
  • limit: limit on the number of characters
  • default: default value of the widget
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • change

    Try change the current value

  • get

    Get the value of the Entry

  • set

    Set the text value of the Entry

  • append

    Append text to Entry

  • delete

    Delete a specified amount of text

  • clear

    Clear the text value of the Entry

change

change(up: bool) -> None

Try change the current value

get

get() -> str

Get the value of the Entry

set

set(value: str) -> None

Set the text value of the Entry

append

append(value: str) -> None

Append text to Entry

delete

delete(count: int) -> None

Delete a specified amount of text

clear

clear() -> None

Clear the text value of the Entry

OptionButton

OptionButton(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: tuple[str, ...] = (),
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    default: int | None = None,
    command: collections.abc.Callable[[int | None], typing.Any] | None = None,
    image: tuple[enhanced.PhotoImage | None, ...] = (),
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    align: typing.Literal["up", "center", "down"] = "center",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A button that has many options to choose

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • default: default value of the widget
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • align: align of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the index of the child toggle button with a value of True. If not, None is

  • set

    Activate the child toggle button for the specified index

get

get() -> int | None

Get the index of the child toggle button with a value of True. If not, None is returned.

set

set(value: int | None, *, callback: bool = False) -> None

Activate the child toggle button for the specified index

ComboBox

ComboBox(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] | None = None,
    *,
    text: tuple[str, ...] = (),
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    default: int | None = None,
    command: collections.abc.Callable[[int | None], typing.Any] | None = None,
    image: tuple[enhanced.PhotoImage | None, ...] = (),
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    align: typing.Literal["up", "down"] = "down",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

An input box that can provide several options

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • text: text of the widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • default: default value of the widget
  • command: a function that is triggered when the button is pressed
  • image: image of the widget
  • anchor: anchor of the widget
  • align: align of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the index of the child toggle button with a value of True. If not, None is

  • set

    Activate the child toggle button for the specified index

get

get() -> int | None

Get the index of the child toggle button with a value of True. If not, None is returned.

set

set(value: int | None, *, callback: bool = False) -> None

Activate the child toggle button for the specified index

Spinner

Spinner(
    master: containers.Canvas | virtual.Widget,
    position: tuple[int, int],
    size: tuple[int, int] = (30, 30),
    *,
    default: float | None = None,
    command: collections.abc.Callable[[float], typing.Any] | None = None,
    widths: tuple[int, int] | None = None,
    mode: typing.Literal["determinate", "indeterminate"] = "determinate",
    anchor: typing.Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
    capture_events: bool | None = None,
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

Spinners visually communicate that something is processing

  • master: parent canvas
  • position: position of the widget
  • size: size of the widget
  • default: default value of the widget
  • command: a function that is triggered when the progress of progress bar is 100%
  • widths: width of the outside ring and inside ring
  • mode: mode of the Spinner
  • anchor: anchor of the widget
  • capture_events: wether detect another widget under the widget
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the progress of the Spinner

  • set

    Set the progress of the Spinner

  • destroy

    Destroy the widget

get

get() -> float

Get the progress of the Spinner

set

set(value: float, *, callback: bool = False) -> None

Set the progress of the Spinner

destroy

destroy() -> None

Destroy the widget

Tooltip

Tooltip(
    widget: virtual.Widget,
    size: tuple[int, int] | None = None,
    *,
    text: str = "",
    align: typing.Literal["up", "down", "right", "left", "center"] = "down",
    padding: int = 3,
    family: str | None = None,
    fontsize: int | None = None,
    weight: typing.Literal["normal", "bold"] = "normal",
    slant: typing.Literal["roman", "italic"] = "roman",
    underline: bool = False,
    overstrike: bool = False,
    justify: typing.Literal["left", "center", "right"] = "left",
    gradient_animation: bool | None = None,
    auto_update: bool | None = None,
    style: type[virtual.Style] | None = None
)

Bases: virtual.Widget

A tooltip that can display additional information

  • widget: the associated widget
  • size: size of the widget
  • text: text of the widget
  • align: align mode of the tooltip
  • padding: extra padding between tooltip and the associated widget
  • family: font family
  • fontsize: font size
  • weight: weight of the text
  • slant: slant of the text
  • underline: whether the text is underline
  • overstrike: whether the text is overstrike
  • justify: justify mode of the text
  • gradient_animation: wether enable gradient_animation
  • auto_update: whether the theme manager update it automatically
  • style: style of the widget

方法:

  • get

    Get the text of the widget

  • set

    Set the text of the widget

get

get() -> str

Get the text of the widget

set

set(text: str) -> None

Set the text of the widget

PhotoImage

Bases: ImageTk.PhotoImage, tkinter.PhotoImage

Pillow version of tkinter.PhotoImage.

方法:

  • scale

    Scale the PhotoImage.

  • resize

    Resize the PhotoImage.

scale

scale(x: float, y: float) -> PhotoImage

Scale the PhotoImage.

  • x: The x-axis scale factor
  • y: The y-axis scale factor

resize

resize(width: int, height: int) -> PhotoImage

Resize the PhotoImage.

  • width: The new width of the image
  • height: The new height of the image

reset

reset() -> None

Reset all configuration options.