maliang.core.virtual¶
字数 9 个 阅读时间不到 1 分钟 访问量
All virtual classes.
The virtual.Widget
consists of five parts, which are Shape
, Text
, Image
, Style
and Feature
. In addition, they can be nested within each other.
Where Feature
is the function of widgets, Style
control the color of the widget, and each widget can be bound to up to one Feature
and one Style
, but in terms of appearance, there is no limit to the number of Shape
, Text
, and Image
.
Shape
, Text
, and Image
are all appearance elements that inherit from abstract base class Elements
.
类:
-
Element
–The basic visible part of a
virtual.Widget
. -
Shape
–The Shape of a
Widget
-
Text
–The Text of a
Widget
. -
Image
–The Image of a
Widget
. -
Style
–The styles of a
Widget
. -
Feature
–The features of a
Widget
. -
Widget
–Base Widget Class.
Element ¶
Element(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs
)
The basic visible part of a virtual.Widget
.
widget
: parent widgetposition
: position relative to its widgetssize
: size of elementname
: name of elementgradient_animation
: Wether use animation to change colorkwargs
: extra parameters for CanvasItem
方法:
-
move
–Move the
Element
. -
moveto
–Move the
Element
to a certain position. -
destroy
–Destroy the
Element
. -
center
–Return the geometric center of the
Element
. -
region
–Return the decision region of the
Element
. -
detect
–Detect whether the specified coordinates are within
Element
. -
update
–Update the style of the
Element
to the corresponding state. -
configure
–Configure properties of
Element
and update them immediately. -
forget
–Let the element to forget.
-
zoom
–Zoom the
Element
. -
display
–Display the
Element
on aCanvas
. -
coords
–Resize the
Element
.
move ¶
Move the Element
.
dx
: x-coordinate offsetdy
: y-coordinate offset
moveto ¶
Move the Element
to a certain position.
x
: x-coordinate of the target locationy
: y-coordinate of the target location
detect ¶
Detect whether the specified coordinates are within Element
.
x
: x-coordinate of the location to be detectedy
: y-coordinate of the location to be detected
update ¶
Update the style of the Element
to the corresponding state.
state
: the state of theElement
gradient_animation
: whether use gradient animation
configure ¶
Configure properties of Element
and update them immediately.
style
: style datagradient_animation
: whether use gradient animation
forget ¶
Let the element to forget.
value
: whether to forgetgradient_animation
: whether use gradient animation
zoom ¶
Zoom the Element
.
ratios
: ratios of zoomingzoom_position
: whether or not to zoom the location of the elementzoom_size
: whether or not to zoom the size of the element
Shape ¶
Shape(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs
)
Text ¶
Text(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
text: str = "",
limit: int = -1,
show: str | None = None,
placeholder: 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,
name: str | None = None,
gradient_animation: bool = True,
**kwargs
)
Bases: Element
The Text of a Widget
.
widget
: parent widgetrelative_position
: position relative to its widgetssize
: size of elementtext
: text valuefamily
: font familyfontsize
: font sizeweight
: weight of the fontslant
: slant of the fontunderline
: wether text is underlineoverstrike
: wether text is overstrikelimit
: limit on the number of charactersshow
: display a value that obscures the original contentplaceholder
: a placeholder for the promptname
: name of elementgradient_animation
: Wether use animation to change colorkwargs
: extra parameters for CanvasItem
方法:
Image ¶
Image(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
name: str | None = None,
gradient_animation: bool = True,
**kwargs
)
Bases: Element
The Image of a Widget
.
widget
: parent widgetrelative_position
: position relative to its widgetssize
: size of elementimage
: image object of the elementname
: name of elementgradient_animation
: Wether use animation to change colorkwargs
: extra parameters for CanvasItem
方法:
Style ¶
The styles of a Widget
.
widget
: parent widgetauto_update
: whether the theme manager update it automatically
方法:
-
get_disabled_style
–Get the style data of disabled state.
-
init
–Initialize some style of an element.
-
get
–Return the style of the widget.
-
reset
–Reset the style of the widget and update.
-
set
–Set the style of the widget.
get_disabled_style ¶
Get the style data of disabled state.
element
: element that style to be calculated
init ¶
Initialize some style of an element.
name
: the key of the elementtheme
: the theme name, None indicates both
get ¶
get(
*, theme: typing.Literal["light", "dark"] | None = None
) -> dict[str, dict[str, dict[str, str]]]
Return the style of the widget.
theme
: the theme of the widget, None indicates the current theme
reset ¶
Reset the style of the widget and update.
theme
: the theme to be reset, None indicates both
Feature ¶
Feature(widget: Widget)
The features of a Widget
.
widget
: parent widget
方法:
-
get_method
–Return method by name.
get_method ¶
get_method(name: str) -> collections.abc.Callable
Return method by name.
name
: name of the method
Widget ¶
Widget(
master: containers.Canvas | Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
anchor: typing.Literal["n", "s", "w", "e", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[Style] | None = None
)
Base Widget Class.
Widget
= Element
+ Style
+ Feature
master
: parent canvasposition
: position of the widgetsize
: size of the widgetanchor
: layout anchor of the widgetcapture_events
: wether detect another widget under the widgetgradient_animation
: wether enable animationauto_update
: whether the theme manager update it automaticallystyle
: style of the widget
方法:
-
register_elements
–Register elements to the widget.
-
deregister_elements
–Deregister a element from the widget.
-
update
–Update the widget.
-
bind_on_update
–Bind an extra function to the widget on update.
-
unbind_on_update
–Unbind an extra function to the widget on update.
-
bind
–Bind to this widget at event sequence a call to function command.
-
unbind
–Unbind for this widget the event sequence.
-
generate_event
–Generate an event sequence. Additional keyword arguments specify
-
disable
–Disable the widget.
-
forget
–Let all elements of the widget to forget.
-
move
–Move the widget.
-
moveto
–Move the Widget to a certain position.
-
destroy
–Destroy the widget.
-
detect
–Detect whether the specified coordinates are within the
Widget
. -
zoom
–Zoom widget ifself.
属性:
-
elements
(tuple[Element, ...]
) –Return all elements of the widget.
-
nested
(bool
) –Whether the widget is a nested widget.
-
offset
(tuple[float, float]
) –Return the offset of the anchor relative to “nw”.
register_elements ¶
register_elements(*elements: Element) -> None
Register elements to the widget.
elements
: elements to be registered
deregister_elements ¶
deregister_elements(*elements: Element) -> None
Deregister a element from the widget.
elements
: elements to be deregistered
update ¶
update(
state: str | None = None, *, gradient_animation: bool | None = None, nested: bool = True
) -> None
Update the widget.
state
: state of the widgetgradient_animation
: whether use gradient animationnested
: whether nested
bind_on_update ¶
Bind an extra function to the widget on update.
This extra function has two positional arguments, both of which are arguments to the method update
. And this extra function will be called when the widget is updated (whether it’s automatically updated or manually updated).
command
: the extra function that is bound
unbind_on_update ¶
Unbind an extra function to the widget on update.
command
: the extra function that is bound
bind ¶
bind(
sequence: str,
command: collections.abc.Callable[[tkinter.Event], typing.Any],
add: bool | typing.Literal["", "+"] | None = None,
*,
auto_detect: bool = True
) -> None
Bind to this widget at event sequence a call to function command.
sequence
: event namecommand
: callback functionadd
: if True, original callback function will not be overwrittenauto_detect
: Automatically determine whether to execute binding events based on the methoddetect
unbind ¶
Unbind for this widget the event sequence.
sequence
: event namecommand
: callback function
generate_event ¶
Generate an event sequence. Additional keyword arguments specify parameter of the event.
sequence
: event nameevent
: eventkwargs
: attr of event
forget ¶
forget(value: bool = True) -> None
Let all elements of the widget to forget.
value
: whether to forget the widget
move ¶
Move the widget.
dx
: x-coordinate offsetdy
: y-coordinate offset
moveto ¶
Move the Widget to a certain position.
x
: x-coordinate of the target locationy
: y-coordinate of the target location
detect ¶
Detect whether the specified coordinates are within the Widget
.
x
: x-coordinate of the location to be detectedy
: y-coordinate of the location to be detected