maliang.core¶
字数 11 个 阅读时间不到 1 分钟 访问量
The core code, you can see the general framework here.
Most of the abstract and base classes are defined here.
模块:
-
configs
–All global configuration options.
-
containers
–All containers.
-
virtual
–All virtual classes.
类:
-
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
–Reset all configuration options.
-
get_default_system
–Get the system of environment.
Font ¶
Configurations for default font.
方法:
-
reset
–Reset all configuration options.
-
get_default_family
–Get the default font family.
Constant ¶
All Constants.
属性:
-
GOLDEN_RATIO
(typing.Final[float]
) –The golden ratio, which is needed to automatically calculate the color
-
PREDEFINED_EVENTS
(typing.Final[tuple[str, ...]]
) –Predefined events that can be used directly without registration. It is
-
PREDEFINED_VIRTUAL_EVENTS
(typing.Final[tuple[str, ...]]
) –Predefined virtual events that can be used directly without
GOLDEN_RATIO class-attribute
instance-attribute
¶
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.
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
)
Main window.
In general, there is only one main window. But after destroying it, another one can be created.
size
: size of the windowposition
: 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 classtkinter.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.
属性:
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 nameinclude_children
: wether include its children, like Toplevelinclude_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 anythingposition
: 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.
alpha ¶
Set or get the transparency of the window
value
: the transparency of the window, range is 0~1
topmost ¶
Set or get whether the window is pinned or not
value
: indicate whether the window is topmost
fullscreen ¶
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 ¶
Set or get whether the window is tool-window.
value
: indicate whether the window is tool-window
This method only works on Windows!
transparentcolor ¶
Set or get the penetration color of the window.
value
: the penetration color of the window
This method only works on Windows!
modified ¶
Set or get whether the window is modified.
value
: indicate whether the window is modified
This method only works on macOS!
transparent ¶
Set or get whether the window is transparent.
value
: indicate whether the window is transparent
This method only works on macOS!
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 widgetsize
: size of the window, default value is 960x540(px)position
: position of the window, default value indicates randomtitle
: title of window, default is the same as title of mastericon
: icon of the window, default is the same as title of mastergrab
: set grab for this windowfocus
: whether direct input focus to this window**kwargs
: compatible with other parameters of classtkinter.Toplevel
方法:
-
destroy
–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
)
Main contrainer: Canvas.
The parent widget of all virtual widgets is Canvas
.
master
: parent widgetexpand
: the mode of expand,x
is horizontal, andy
is verticalauto_zoom
: whether or not to scale its items automaticallykeep_ratio
: the mode of aspect ratio,min
follows the minimum value,max
follows the maximum valuefree_anchor
: whether the anchor point is free-floatingauto_update
: whether the theme manager update it automaticallyzoom_all_items
: (Experimental) whether or not to scale its all itemskwargs
: compatible with other parameters of classtkinter.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.
属性:
theme ¶
Change the color theme of the Canvas and its items
value
: theme name
zoom ¶
Resize and position the Canvas
based on the relevant parameters.
This method only works for Canvas with Place layout.
create_text ¶
Create text with coordinates x, y.
on_wheel ¶
Events to scroll the mouse wheel
register_event ¶
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.