跳转至

maliang.core

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

源代码:maliang/core/__init__.py

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

Most of the abstract and base classes are defined here.

模块:

类:

  • Env

    Configurations for default environment values.

  • Font

    Configurations for default font.

  • Constant

    All Constants.

  • Tk

    Main window.

  • Toplevel

    Toplevel window.

  • Canvas

    Main contrainer: Canvas.

函数:

  • 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.

reset

reset() -> None

Reset all configuration options.