tkmilan.model#

Models to store complex information in unambiguous ways.

Mostly implemented as dataclasses.

Module Attributes

TraceModeT

The supported operations to watch for a trace.

ValidateWhenT

The supported validation modes, to be set when arguments.

ValidateWhyT

The supported validation modes, to be given for why arguments.

ValidateST

The supported validation action types.

NotebookTabStateT

The supported NotebookTab state types.

CSIZE

Pixel Coordinate Logging Size.

IMAGE_TYPES

Supported image types, and corresponding loaders.

Alignment_CP

Conversion between numeric positioning and CP.

CP_Compound

The compound configuration setting.

CP_ScrollAnchor

The ScrolledWidget/Scrolled scroll anchor configuration setting.

CP_S

The sticky configuration setting.

Justification_CP

Conversion between Justification and CP objects.

GUI_STATES

GuiState Tk metadata.

GUI_STATES_common

GuiState common to all widgets.

Classes

Binding(widget, sequence, *args, **kwargs)

Wrap a stateful binding.

BindingGlobal(widget, sequence, *args, **kwargs)

Wrap a stateful global binding.

BindingTag(widget, tag, sequence, *args, ...)

Wrap a stateful tag binding for EntryMultiline.

CP(value)

A Cardinal Point.

DStyle(value)

Dynamic Widget Style Options.

Direction(value)

The direction of automatic widget layout.

EventModifier(value)

Event Modifier bitfield object

FileType(*args)

FileTypes

GridCoordinates(row, column[, rowspan, ...])

Widget Grid Coordinates.

GridSize(rows, columns)

Widget Grid Size.

GuiState([enabled, valid, readonly, alternate])

Widget GUI state.

GuiState_Tk(string, invert)

Information about Tk states.

ImageCache([obj, fname, data, dtype])

Image Cache metadata.

Interval(widget, action, interval[, immediate])

Repeat an action with an interval between calls.

Justification(value)

A text justification anchor.

MenuElement()

Common menu element class.

MenuElementCascade(label, children, id[, ...])

Menu Element: Cascading Menu.

MenuElementCheckbox(label, variable, id)

Menu Element: Checkbox

MenuElementLabel(label, id)

Menu Element: Label.

MenuElementRadio(label, variable, value, id)

Menu Element: Radio Button.

MenuElementSeparator(id)

Menu Element: Separator.

MixinBinding(widget, sequence, action, *[, ...])

NotebookTab(name, widget, image, extra, ...)

Information for each Notebook tab.

NotebookTabOrder(shown, *[, disabled])

Information for all Notebook tab ordering.

PixelSize(w, h)

Hold a size, in pixels.

RateLimiter(widget, action, limit)

Rate Limit an action.

SStyle()

Static Widget Style Options.

Sticky([N, S, E, W])

The grid sticky configuration.

TextElement()

Common text element class.

TextElementInline(text, tag, tags, data, str] =)

Text Element: An inline text span, with optional tags.

TextElement_br()

Text Element: Line break.

Timeout(widget, action, timeout[, immediate])

Schedule an action into the future time, cancellable.

TimeoutIdle(widget, action[, immediate])

Schedule an action into the future, whenever there's nothing else to do.

TreeColumn(name[, identifier, stretch, ...])

Configuration for each tkmilan.Tree column.

TreeElement(label[, columns, children, ...])

Information for each tkmilan.Tree record.

TreeRow([foreground, background, font, image])

Configuration for each tkmilan.Tree row.

VSettings([postFocusIn, postFocusOut, ...])

Hold validation settings.

VState(label[, value])

Hold validated state.

VWhy(vstate, why, t, widget, tt)

Validation runtime information.

WState(state, substate)

Hold wrapped state.

WStateR(state, substate)

Reversed version of the WState state.

WStyle([_default])

Widget style object.

WidgetDynamicState(getter, setter, noneable)

Hold the dynamic state for a widget.

WidgetGeometry(x, y[, w, h])

Hold the geometry information for a widget.

WidgetView(xview, yview)

Hold the view information for a widget.

WindowState(fullscreen)

GUI State for entire windows.

class tkmilan.model.Binding(widget: mixin.MixinWidget, sequence: str, *args, **kwargs)#

Bases: MixinBinding

Wrap a stateful binding.

Can be enabled and disabled separately from creation. Default to starting disabled. Note that this is the opposite from the actions of the wrapped functions.

See Python documentation for bindings and events.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the binding to.

  • sequence (str) – The sequence to bind to. See Tk bind documentation, not everything applies here.

  • action – The function to call when the binding is hit.

  • immediate – Enable binding on creation. Defaults to False, requiring separate activation.

  • description – Optional description of the binding action. Useful for debugging, not used for any purpose for now.

Note

When the action function returns "break", no more actions are considered. Use this with care.

See also

For the global version of this, see BindingGlobal.

__bool__()#

Check if the binding is enabled.

Should be used as:

if binding:
    print('Binding is enabled')
else:
    print('Binding is disabled')
enable(*, warn: bool = True) None#

Enable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use tryenable to force warn to False.

tryenable() bool#

Try to enable the binding, don’t warn when already enabled.

Wraps enable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

disable(*, warn: bool = True) None#

Disable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use trydisable to force warn to False.

trydisable() bool#

Try to disable the binding, don’t warn when already disabled.

Wraps disable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

class tkmilan.model.BindingGlobal(widget: mixin.MixinWidget, sequence: str, *args, **kwargs)#

Bases: MixinBinding

Wrap a stateful global binding.

This is a global version of the Binding object. The main difference is that the widget argument is ignored, the binding applies to the entire application (technically, the widget’s mixin.MixinWidget.wroot (a RootWindow).

The RootWindow will store a dictionary of sequences to BindingGlobal. This is similar to mixin.MixinWidget.binding.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the binding to. This can be any widget, only the corresponding RootWindow is considered.

  • sequence (str) – The sequence to bind to. See Tk bind documentation, not everything applies here.

  • action – The function to call when the binding is hit.

  • immediate – Enable binding on creation. Defaults to False, requiring separate activation.

  • description – Optional description of the binding action. Useful for debugging, not used for any purpose for now.

Note

When the action function returns "break", no more actions are considered. Use this with care.

See also

For the widget version of this, see Binding.

__bool__()#

Check if the binding is enabled.

Should be used as:

if binding:
    print('Binding is enabled')
else:
    print('Binding is disabled')
enable(*, warn: bool = True) None#

Enable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use tryenable to force warn to False.

tryenable() bool#

Try to enable the binding, don’t warn when already enabled.

Wraps enable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

disable(*, warn: bool = True) None#

Disable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use trydisable to force warn to False.

trydisable() bool#

Try to disable the binding, don’t warn when already disabled.

Wraps disable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

class tkmilan.model.BindingTag(widget: EntryMultiline, tag: str, sequence: str, *args, **kwargs)#

Bases: MixinBinding

Wrap a stateful tag binding for EntryMultiline.

This is a version of the Binding object which applies only to the tags in EntryMultiline.

Parameters:
  • widget (EntryMultiline) – The widget to apply the binding to. This can be any widget, only the corresponding RootWindow is considered.

  • tag (str) – The sub-widget tag where the binding applies.

  • sequence (str) – The sequence to bind to. See Tk bind documentation, not everything applies here.

  • action – The function to call when the binding is hit.

  • immediate – Enable binding on creation. Defaults to False, requiring separate activation.

  • description – Optional description of the binding action. Useful for debugging, not used for any purpose for now.

Note

When the action function returns "break", no more actions are considered. Use this with care.

__bool__()#

Check if the binding is enabled.

Should be used as:

if binding:
    print('Binding is enabled')
else:
    print('Binding is disabled')
enable(*, warn: bool = True) None#

Enable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use tryenable to force warn to False.

tryenable() bool#

Try to enable the binding, don’t warn when already enabled.

Wraps enable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

disable(*, warn: bool = True) None#

Disable the binding.

Parameters:

warn (bool) – Warn about redundant operations. Enabled by default.

See also

Use trydisable to force warn to False.

trydisable() bool#

Try to disable the binding, don’t warn when already disabled.

Wraps disable, with warn forced to False.

Returns:

A bool indicating if the state has changed.

Return type:

bool

class tkmilan.model.CP(value)#

Bases: Enum

A Cardinal Point.

Usually, this defines an anchor point for alignment.

Corresponds neatly to the same tkinter values, but it’s simpler to validate as an enum.

Here is a table of cardinal points, for visual reference:

Table 1 Cardinal Points#

NW

N

NE

W

center

E

SW

S

SE

E = 'e'#

East

N = 'n'#

North

NE = 'ne'#

NorthEast = N + E

NW = 'nw'#

NorthWest = N + W

S = 's'#

South

SE = 'se'#

SouthEast = S + E

SW = 'sw'#

SouthWest = S + W

W = 'w'#

West

center = 'center'#

Center element on the container. Not a “cardinal point” in the usual sense.

default = None#

OS-specific cardinal point.

class tkmilan.model.DStyle(value)#

Bases: Enum

Dynamic Widget Style Options.

These objects are replaced by the corresponding values, calculated dynamically from the theme values.

See also

SStyle for static style values.

Color_BG = 2#

Normal Widgets background

Type:

Color

Color_BG_Selected = 4#

Selected Widgets background

Type:

Color

Color_FG = 1#

Normal Widgets foreground

Type:

Color

Color_FG_Disabled = 3#

Disabled Widgets foreground

Type:

Color

Font_Default = 5#

Default Font

Type:

Font

class tkmilan.model.Direction(value)#

Bases: Enum

The direction of automatic widget layout.

Here is a table of direction “cardinal points”, for visual reference:

Table 2 Direction Cardinal Points#

N

H

W

E

V

S

Note

This is similar to CP, but should not be confused with it.

grid(rows: int, cols: int, amount: int | None = None, auto_fill: bool = True) Iterable[GridCoordinates]#

Generate GridCoordinates for a widget grid.

If the amount of widgets to distribute is not given, this assumes the coordinates are calculated for an uniform grid (all spaces occupied).

This amount must fit on the grid, which mean rejecting amounts of widgets that leave an entire row or column unfilled. The auto_fill flag controls adjusting the last widget to completely fill the available space.

Parameters:
  • rows (int) – Number of rows on the grid

  • cols (int) – Number of columns on the grid

  • amount (int | None) – Number of widgets to distribute. Optional, defaults to having all the grid positions fulfilled.

  • auto_fill (bool) – Adjust the missing widgets by expanding the last one to fill the rest of the empty space. Defaults to enable.

multiples(*amounts: int | None, amount: int | None = None) Iterable[GridCoordinates]#

Generate GridCoordinates for sequence of integer amounts.

amounts is a series of integers or None (refered to as “slots”), to be distributed per row/column, depending on the direction.

There can be any number of “slots”, marking a row/column as receiving the remaining widgets. The remaining widgets are distributed evenly through the existing “slots”.

If the amount of widgets to distribute is not given, there is no support for using None as amount. Another possible error is giving an amount of slots that do not evenly divide the remaining widgets.

Parameters:
  • amounts (int | None) – Amount of widgets per row/column.

  • amount (int | None) – Number of widgets to distribute. Optional.

E = (0, 1)#

East

H = (-1, 1)#

Reversed Horizontal, combines North and East

N = (-1, 0)#

North

S = (1, 0)#

South

V = (1, -1)#

Reversed Vertical, combines South and West

W = (0, -1)#

West

class tkmilan.model.EventModifier(value)#

Bases: Enum

Event Modifier bitfield object

Includes all supported event modifier checks.

There is no Python documentation, nor Tk documentation anywhere. This list was created by trial and error.

You can read some semi-official references related to this:

Note

The documentation shows the values for the OS where the documentation is built (usually Linux). The values might be different on other platforms, like Windows.

on(event: Event) bool#

Check if the modifier is being applied in the given event.

Very useful to check if modifiers are being applied in a cross-platform manner. Use like this:

def onEvent(self, event):
    if EventModifier.Control.on(event):
        print('Pressing Control')
Alt = 8#

The Alt key

AltGr = 128#

The AltGr key.

On Windows, this is equivalent to Ctrl and Alt.

CapsLock = 2#

The CapsLock lock key.

This is a lock key, can be active even if the user is not clicking any key.

Control = 4#

The Ctrl key

NumLock = 16#

The NumLock lock key.

This is a lock key, can be active even if the user is not clicking any key.

ScrollLock = None#

The ScrollLock lock key.

On Linux, this might not be supported.

This is a lock key, can be active even if the user is not clicking any key.

Shift = 1#

The Shift key

class tkmilan.model.FileType(*args: str)#

Bases: Tuple[str]

class tkmilan.model.FileTypes#

Bases: Dict[str, FileType]

class tkmilan.model.GridCoordinates(row: int, column: int, rowspan: int = 1, columnspan: int = 1)#

Bases: object

Widget Grid Coordinates.

This includes information about widgets, even if they span more than one row or column. It should fully specify the widget grid location.

The “location string” format is the following: R[+RS]xC[+CS]

  • R: Row

  • RS: Row Span (optional, defaults to 1)

  • C: Column

  • CS: Column Span (optional, defaults to 1)

__str__()#

Convert the grid coordinates into a “location string”.

For the reverse operation, see parse.

columns() Iterator[int]#

Generate all grid column indexes spanned by the widget.

dict(*, dict_factory=<class 'dict'>)#

Get this information as a dictionary.

classmethod parse(string: str) GridCoordinates#

Parse a “location string” to a grid coordinates object.

For the reverse operation, convert the object to str (see __str__).

rows() Iterator[int]#

Generate all grid row indexes spanned by the widget.

tuple(*, tuple_factory=<class 'tuple'>)#

Get this information as a tuple.

Note

The order of fields is not ideal.

class tkmilan.model.GridSize(rows: int, columns: int)#

Bases: object

Widget Grid Size.

This includes information about all child widgets for a container.

tuple(*, tuple_factory=<class 'tuple'>)#

Get this information as a tuple.

class tkmilan.model.GuiState(enabled: bool | None = None, valid: bool | None = None, readonly: bool | None = None, alternate: bool | None = None)#

Bases: object

Widget GUI state.

This supports all possible states, not all widgets support all states.

See GUI_STATES, mixin.MixinWidget.gstate.

isCustom() bool#

Check if this is a custom object.

Basically, returns True when this is a subclass on GuiState. Useful to detect states with slighly different semantics.

items()#

Workaround for dataclasses.asdict issue.

This is a problem-free version of:

return dataclasses.asdict(self).items()
classmethod new(state: GuiState) GuiState#

Create a new object with the same state.

For performance reasons, since they are readonly on the common case, the GuiState objects are passed through the hierarchy by reference.

If you need to make changes to a received object, create a new object using this function.

states_tk(*, widget: Optional[mixin.MixinWidget] = None) Sequence[str]#

Calculate the Tk string to use with state functions.

See the state function.

Parameters:

widget (Optional[mixin.MixinWidget]) – Widget to validate if the generated state is consistent with supported keys. Optional.

class tkmilan.model.GuiState_Tk(string: str, invert: bool)#

Bases: object

Information about Tk states.

The states applied to the widgets are very confusing, so store all the necessary metadata here.

See GuiState, GUI_STATES, GUI_STATES_common.

Example

The examples will analyse GUI_STATES.

The simplest example is the "readonly" element. The Tk string is readonly, so invert is False, the semantic values match.

On the other hand, for the "enabled" element, the Tk string is disabled, so invert is True. The semantic values are inverted.

gstr() str#

Calculate the Tk string to obtain the value.

This already takes into account the invert parameter.

See the instate function.

sstr(value: bool) str#

Calculate the Tk string to define the value.

This already takes into account the invert parameter.

See the state function.

invert: bool = <dataclasses._MISSING_TYPE object>#

Is the string state the opposite from its sematic value?

string: str = <dataclasses._MISSING_TYPE object>#

The Tk string used in the state-releated functions.

class tkmilan.model.ImageCache(obj: Image | None = None, fname: Path | None = None, data: bytes | None = None, dtype: str | None = None)#

Bases: object

Image Cache metadata.

Each cached image has metadata associated with it, to be able to support lazy-loading images.

The obj point to the image object, the rest are metadata used to reconstruct it.

property cached: bool#

Check if the image object is cached.

class tkmilan.model.Interval(widget: mixin.MixinWidget, action: Callable, interval: int, immediate: bool = False)#

Bases: object

Repeat an action with an interval between calls.

Can be scheduled and unscheduled separately from creation, see the immediate argument.

Uses a Timeout internally.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the interval to. When in doubt, use the wroot widget.

  • action (Callable) – The function to call when the interval elapses.

  • interval (int) – The interval time, in milliseconds. This only starts to count from the scheduling time, not the object creation, but see immediate.

  • immediate (bool) – Schedule interval on creation. Defaults to False, set to True to schedule automatically.

See also

To run the action only once, see Timeout.

doState_Trace(variable: var.Variable, etype: str | None) None#

“Glue” the traced variable state to this interval state.

This should be attached to the trace as the callback function. It will change the interval state (using reschedule/tryunschedule) based on the variable state.

Considers the boolean value for the variable contents, see truth value testing documentation.

Works for all variable types, but should be restricted to var.Boolean. If you attach a non-boolean variable type, there is a warning on debug mode.

reschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Reschedule the interval.

If the interval is already scheduled, this resets the interval, so it starts ticking from this point. If the interval is unscheduled, it schedules it.

Either way, after interval milliseconds of calling this function, the action will run.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

schedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Schedule the interval to start ticking.

The countdown for expiration of interval milliseconds starts when this function is called.

Make sure the interval is not scheduled already. When in doubt, use reschedule instead.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

tryunschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None, *, force: bool = False) None#

Try cancelling the interval.

Call unschedule only if the interval is already scheduled, it’s a no-op otherwise. All arguments are passed through.

Parameters:
  • force (bool) – Unschedule on-flight interval, if exists. Disabled by default.

  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

See also

See unschedule for the underlying function.

unschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None, *, force: bool = False) None#

Cancel the interval.

This cancels the interval repetion, but after calling this function, the action might still run, at most once. See force to control this behaviour.

Parameters:
  • force (bool) – Unschedule on-flight interval, if exists. Disabled by default.

  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

scheduled: bool#

Scheduled State.

Checks if the interval is scheduled to repeat.

The state is one of the following:

  • True: Scheduled, the action will be repeated forever.

  • False: Unscheduled, but the action might be repeated once again at most.

class tkmilan.model.Justification(value)#

Bases: Enum

A text justification anchor.

Corresponds to neatly to the same tkinter values, but it’s simpler to validate as an enum.

Note

Not all widgets support NoJustify, sometimes it’s necessary to not pass the justify option at all.

Center = 'center'#

Justify Center

Left = 'left'#

Justify Left

NoJustify = None#

OS-specific justification.

Right = 'right'#

Justify Right

class tkmilan.model.MenuElement#

Bases: ABC

Common menu element class.

This is only an abstract class, a common base class for all the possible menu types.

Parameters:
  • id – The menu identifier.

  • variable – The menu variable object. Can be None.

property container: bool#

Mark menu element as a single element

class tkmilan.model.MenuElementCascade(label: str, children: Tuple[MenuElement, ...], id: str, wstate_single: bool | None = None)#

Bases: MenuElement

Menu Element: Cascading Menu.

Represents a simple label with an attached child menu. This is similar to FrameLabelled.

Parameters:
  • label (str) – The menu label.

  • children (Tuple[MenuElement, ...]) – The child elements. Can include other MenuElementCascade. There should be at least one child element.

  • wstate_single (bool | None) – Mark child menu with wstate_single. Optional, defaults to not marking it.

  • id (str) – The menu identifier.

Note

The label cannot accept newlines.

property container: bool#

Mark menu element as container, with children

class tkmilan.model.MenuElementCheckbox(label: str, variable: var.Boolean, id: str)#

Bases: MenuElement

Menu Element: Checkbox

Represents a checkbox. The state is always boolean.

Equivalent to Checkbox.

Parameters:
  • label (str) – The menu label.

  • variable (var.Boolean) – The variable object.

  • id (str) – The menu identifier.

Note

The label cannot accept newlines.

class tkmilan.model.MenuElementLabel(label: str, id: str)#

Bases: MenuElement

Menu Element: Label.

Represents a simple label, can be clicked.

Equivalent to Button (or Label, if you do not care about events).

Parameters:
  • label (str) – The menu label.

  • id (str) – The menu identifier.

Note

The label cannot accept newlines.

class tkmilan.model.MenuElementRadio(label: str, variable: var.SpecParsed[merT], value: merT, id: str)#

Bases: MenuElement, Generic[merT]

Menu Element: Radio Button.

Represents a single radio button element. Usually, a series of these are required, sharing the same variable, to set the variable between one of the values.

Equivalent to Radio.

Parameters:
  • label – The menu label.

  • variable – The variable object.

  • value – The value for this particular menu.

  • id – The menu identifier.

class tkmilan.model.MenuElementSeparator(id: str)#

Bases: MenuElement

Menu Element: Separator.

Represents a separator, an horizontal line.

Equivalent to SeparatorH.

Parameters:

id (str) – The menu identifier.

class tkmilan.model.NotebookTab(name: str, widget: mixin.ContainerWidget, image: ~tkinter.Image | None = None, extra: ~typing.Mapping[str, ~typing.Any] = <factory>, labelPosition: dataclasses.InitVar[typing.Union[ForwardRef('CP'), bool, NoneType]] = CP.E)#

Bases: object

Information for each Notebook tab.

These are the parameters which can be configured:

Parameters:
  • name (str) – The visible text on the tab itself

  • widget (mixin.ContainerWidget) – The widget corresponding to the tab. Must be a container.

  • image (Image | None) – Show an icon on the tab. Optional.

  • extra (Mapping[str, Any]) – more arguments to the add function. This is an escape hatch, optional.

  • labelPosition (dataclasses.InitVar[Union[ForwardRef('CP'), bool, NoneType]]) –

    When the “image” is set, adjust the label position. When set to CP.default, only the image is included and no label is shown.

    Defaults to CP.E, not available on the object.

There are other parameters which are automatically calculated:

Parameters:
  • identifier – The internal tab identifier. Set by the widget itself.

  • imageCompound – The compound settings. Based on “labelPosition”, automatically calculated.

Note

Technically, it is possible to have single widgets as “widget”, but this results in broken layouts.

property tk_idx: str#

Get the Tk index to be used on upstream functions as needed.

This uniquely identifies the correct tab.

class tkmilan.model.NotebookTabOrder(shown: Iterable[str], *, disabled: Iterable[str] | None = None)#

Bases: object

Information for all Notebook tab ordering.

These are the parameters which can be configured:

Parameters:
  • shown (Sequence[str]) – Tab identiers to be shown, either on normal and disable modes. Mandatory.

  • disabled (Set[str]) – Tab identifiers to be shown as disabled. Optional, defaults to an empy set.

Other parameters are automatically calculated:

active: Tab identifiers to be show as active.

tk_states(allidx: Iterable[str]) Iterator[Tuple[str, int | None, Literal['normal', 'disabled', 'hidden']]]#

Generate Tk information about all NotebookTab.

Given all the possible tab identifiers, generate tuples with the following information:

Parameters:

allidx (Iterable[str]) – All NotebookTab identifiers.

class tkmilan.model.PixelSize(w: int, h: int)#

Bases: object

Hold a size, in pixels.

Parameters:
  • w (int) – Width.

  • h (int) – Height.

reduce(ratio: int) PixelSize#

Divide the size by the given ratio.

This uses integer division.

tuple(*, tuple_factory=<class 'tuple'>)#

Get this information as a tuple.

property aspect_ratio: Fraction#

Calculate the aspect ratio for the size.

There is no loss of precision.

class tkmilan.model.RateLimiter(widget: mixin.MixinWidget, action: Callable, limit: int)#

Bases: object

Rate Limit an action.

Define an action and a time limit. No matter how often you hit this object, the time between actions is never less than the limit (in milliseconds).

It’s ready to use automatically, there’s no need to “schedule” it, like Timeout. Uses a Timeout internally.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the interval to. When in doubt, use the wroot widget.

  • action (Callable) – The function to rate limit.

  • limit (int) – The rate-limit, in milliseconds. The action function is called at most once every this time.

See also

See also other time-related classes like Interval and Timeout.

cancel(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Cancel the next action execution.

This cancels an action execution, when one is pending.

Be advised, this means a triggered action WILL NOT RUN. When used for event processing, means events will be lost. Make sure you know what you are doing.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

hit(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) bool#

Mark the action as “active”.

When this function is called, the action may or may not run, depending on the last time it ran. If the rate limit is respected, the action runs, otherwise it will wait at least the limit time. Calling this function again before the limit is elapsed will reset the timer.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

Returns:

If the action ran this time, return True, otherwise return False.

Return type:

bool

class tkmilan.model.SStyle#

Bases: object

Static Widget Style Options.

These objects are just common values, useful in several locations. They must be calculated once, but used everywhere.

See also

DStyle for static style values.

Note

This is technically a class, but should not be instanced, it only matters to join all values in a single logical location.

classmethod items()#

Get a list of names and values.

Similar to dict.items. Mostly useful for debug.

Font_Button_Small: str = 'TkSmallCaptionFont'#

Font for making a Button as small as possible.

This will keep the button somewhat visible.

See also Size_PadButton_Small.

Type:

Font

Size_PadButton_Small: str = '-1'#

padding for making a Button as small as possible.

This will keep the button somewhat visible.

See Font_Button_Small.

Type:

Size

Size_PadTooltip_X: int = 5#

padding for Tooltip adjustment on the X axis.

This will add a small gap between the widget and the tooltip, for positions CP.W or CP.E.

See Tooltip.adjustGeometry.

Type:

Size

Size_PadWidget_FrameSeparator: int = 8#

padding with the same size as a frame separator (e.g. FrameLabelled, FrameStateful, FrameRadio).

When stacking a FrameRadio and a Radio button vertically, pad the Radio widget on the left side and align it to the left, to obtain aligned Radio widgets.

Type:

Size

Size_TreeHeader_Height: int = 23#

Common height for the Tree header.

Useful to force the height of widgets located “inside” the header.

Type:

Size

Size_Window_OOBDelta: Tuple[int, int, int, int] = (0, 0, 0, 0)#

Window Out-of-Bounds adjustment delta.

These are static adjustments, heuristics based on regular OS uses.

See fn.window_center.

Type:

Size

Size_YF_Frame: int = -19#

y for insetting a frame in a complex frame.

Works for FrameLabelled and friends: FrameStateful, FrameRadio, etc.

Type:

Size

class tkmilan.model.Sticky(N: bool = False, S: bool = False, E: bool = False, W: bool = False)#

Bases: object

The grid sticky configuration.

This defines the sticky configuration for grid settings. Each of the cardinal points can be “stuck” independently. If no cardinal point is “stuck”, the widget will be centered.

There is no Python documentation, see Tk grid configure sticky documentation.

Note

This is just the model object. See the global S class for usage.

classmethod fromtk(string: str) Sticky#

Gather Sticky configuration from a Tk string.

Parameters:

string (str) – The string to process, Tk sticky configuration.

See also

This is the reverse of the tk_sticky function.

classmethod fromwidget(widget: Widget | Tk) Sticky | None#

Gather Sticky configuration from a widget object.

Parameters:

string – The string to process, Tk sticky configuration.

Returns:

Returns a Sticky object with the widget information, if the widget supports and is configured in a grid. Otherwise, returns None.

Return type:

Sticky | None

property tk_sticky: str#

Calculate the “grid sticky string”.

This is mostly used on Tk functions.

class tkmilan.model.TextElement#

Bases: ABC

Common text element class.

This is only an abstract class, a common base class for all the possible text elements.

class tkmilan.model.TextElementInline(text: str, tag: str | None = None, tags: ~typing.Sequence[str] | None = None, data: ~typing.Mapping[str, str] = <factory>)#

Bases: TextElement

Text Element: An inline text span, with optional tags.

This is the most basic text element, just some inline string. It can optionally define one main tag, and other secondary tags to apply to the text.

Parameters:
  • text (str) – The string of text. Mandatory

  • tag (str | None) – The main tag for the text. Optional.

  • tags (Sequence[str] | None) – A list of secondary tags. Optional.

  • data (Mapping[str, str]) – A dictionary of data-* attributes. Default to an empty dictionary.

Note

Setting secondary tags without a main tag is invalid.

property atags#

Get all tags defined in the element.

class tkmilan.model.TextElement_br#

Bases: TextElement

Text Element: Line break.

This is equivalent to a TextElementInline with "\n" as text.

class tkmilan.model.Timeout(widget: mixin.MixinWidget, action: Callable, timeout: int, immediate: bool = True)#

Bases: object

Schedule an action into the future time, cancellable.

The timeout argument (also in schedule) acts as a deadline, after which the action is invoked.

Can be scheduled and unscheduled separately from creation, see the immediate argument.

See Tcl after documentation.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the timeout to. When in doubt, use the wroot widget.

  • action (Callable) – The function to call when the timeout expires.

  • timeout (int) – The expiration time for the timeout, in milliseconds. This only starts to count from the scheduling time, not the object creation, but see immediate.

  • immediate (bool) – Schedule timeout on creation. Defaults to True, set to False to schedule separately.

See also

For the idling version of this, see TimeoutIdle.

isScheduled() bool#

Check if the timeout is scheduled to run in the future.

This is True after calling schedule, and before the action runs.

isTriggered() bool#

Check if the timeout has been triggered yet.

This is True just before the action runs. Note that isScheduled will return False in this case.

reschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None, *, timeout: int | None = None) None#

Reschedule the timeout (alias for schedule).

schedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None, *, timeout: int | None = None) None#

Schedule the timeout to run in the future.

This tries to unschedule the timeout, and schedules it again, to avoid possible race conditions. The countdown for the expiration in timeout milliseconds starts when this function is called.

Note the override values only take effect in this particular call, they are not permanent changes.

Parameters:
  • timeout (int | None) – Override the timeout to consider on the next call.

  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

toggle(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) bool#

Toggle the schedule state.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

Returns:

Return the new state, equivalent to calling isScheduled right afterwards.

Return type:

bool

unschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Cancel the timeout.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

class tkmilan.model.TimeoutIdle(widget: mixin.MixinWidget, action: Callable, immediate: bool = True)#

Bases: object

Schedule an action into the future, whenever there’s nothing else to do.

This adds an idle task to the tk event loop, to be invoked when there’s no other action to take. This is very useful to push actions to the future, but not block the UI thread.

Can be scheduled and unscheduled separately from creation, see the immediate argument.

See tcl after idle documentation.

Parameters:
  • widget (mixin.MixinWidget) – The widget to apply the timeout to. When in doubt, use the wroot widget.

  • action (Callable) – The function to call when the application goes idle.

  • immediate (bool) – Schedule timeout on creation. Defaults to True, set to False to schedule separately.

See also

For a version of this that specifies a deadline, see Timeout.

isScheduled() bool#

Check if the timeout is scheduled to run in the future.

This is True after calling schedule, and before the action runs.

isTriggered() bool#

Check if the timeout has been triggered yet.

This is True after the action runs. Note that isScheduled will return False in this case.

Note

During the action function call, this is False, and it will never be True if it calls reschedule inside the action.

reschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Reschedule the timeout (alias for schedule).

schedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Schedule the timeout to run in the future.

This tries to unschedule the timeout, and schedules it again, to avoid possible race conditions. The action is added to the event loop when this function is called.

When called for an already scheduled object, this is equivalent to moving the action back to the end of the queue.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

toggle(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) bool#

Toggle the schedule state.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

Returns:

Return the new state, equivalent to calling isScheduled right afterwards.

Return type:

bool

unschedule(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None) None#

Cancel the timeout.

This removes the action from the event loop.

Parameters:
  • _arg1 (Any | None) – Unused, included for API compatibility with Tk events

  • _arg2 (Any | None) – Unused, included for API compatibility with Tk traces

  • _arg3 (Any | None) – Unused, included for API compatibility with Tk event loop.

class tkmilan.model.TreeColumn(name: str, identifier: str | None = None, stretch: bool = True, image: Image | None = None, nameAnchor: CP = CP.center, cellAnchor: CP = CP.W)#

Bases: object

Configuration for each tkmilan.Tree column.

This includes settings for both the column heading, and the column cells.

There is no Python documentation, see Tk ttk.Treeview column documentation.

Parameters:
  • name (str) – The heading name, shown on the top of the column

  • identifier (str | None) – The id string. This is not shown to the user. Technically optional, but only when defining the columns, it will always have a str in normal circumstances.

  • stretch (bool) – Adjust the column size when resizing the widget. Defaults to True, automatic resizes.

  • image (Image | None) – Show an icon on the right side of the heading. Optional.

  • nameAnchor (CP) – Anchor the heading name to a CP. Defaults to CP.center.

  • cellAnchor (CP) – Anchor the body column cells to a CP. Defaults to CP.W.

class tkmilan.model.TreeElement(label: str, columns: Sequence[str] | None = None, children: Sequence[TreeElement] | None = None, tags: Sequence[str] | None = None, image: Image | None = None, data: Any | None = None)#

Bases: object

Information for each tkmilan.Tree record.

Technically, this is not enough to reconstruct the entire tree, but it should.

The image argument is optional, but when created, no resizing is performed. By default, the ideal image size is 16x16 pixels.

The tags information indicates which TreeRow configuration applies.

Parameters:
  • label (str) – The leftmost string shown on the first column. This identifies the entire record.

  • columns (Sequence[str] | None) – A list of strings corresponding to the column data. Optional, defaults to None.

  • children (Sequence[TreeElement] | None) – A list of TreeElement, to be shown as children of this TreeElement. This can recurse without limit. Optional, defaults to None.

  • tags (Sequence[str] | None) – Record tags. Optional, defaults to an empty list.

  • image (Image | None) – Show an icon on the left side of the record. Optional.

  • data (Any) – Arbitrary data to store on the element. Optional, defaults to None.

class tkmilan.model.TreeRow(foreground: str | None = None, background: str | None = None, font: str | None = None, image: Image | None = None)#

Bases: object

Configuration for each tkmilan.Tree row.

This includes settings for each TreeElement record, applied by tag.

There is no Python documentation, see Tk ttk.Treeview tag options documentation.

map_tk() Mapping#

Calculate the Tk mapping to use.

There is no Python documentation, see Tk ttk.Treeview tag options documentation.

class tkmilan.model.VSettings(postFocusIn: dataclasses.InitVar[bool] = False, postFocusOut: dataclasses.InitVar[bool] = False, preKey: dataclasses.InitVar[bool] = False, postVar: bool = True, postInitial: bool = True, fn: Callable[[VState, VWhy | None], bool | None] | None = None, fnSimple: bool = True, ttSimple: bool | None = None)#

Bases: object

Hold validation settings.

There are two types of validation, based on timing:

  • Pre-Validation: Validate the future state before the widget state changes. Allows for choosing whether to accept or reject the edit. Does not affect the GuiState.

    This is not very common, since the UX is not very good.

  • Post-Validation: Validate the current widget state, and change the GuiState. This is the most common validation.

There are also native validations (supported by Tk), and synthetic validations, implemented inside this library.

Parameters:
  • postFocusIn (dataclasses.InitVar[bool]) – Post-Validate on widget getting focus. Native validation.

  • postFocusOut (dataclasses.InitVar[bool]) – Post-Validate on widget losing focus. Native validation.

  • preKey (dataclasses.InitVar[bool]) – Pre-Validate on widget getting a key event. Native validation.

  • postVar (bool) – Post-Validate on widget variable changing. Synthetic validation, uses self as ValidateWhyT.

  • postInitial (bool) – Post-Validate on widget creation. Synthetic validation, uses initial as ValidateWhyT.

  • fn (Callable[[VState, VWhy | None], bool | None] | None) – The parsing function, to validate the state. Optional, each widget has a “natural” parsing function.

  • fnSimple (bool) – Do not calculate the full validation data, send only the widget state. This is usually the only thing that matters. Defaults to enabled, for performance reasons.

  • tt – The corresponding Tooltip for this widget, if available. This is paired with the putTooltip function. Optional, not to be used directly.

  • ttSimple (bool | None) – When True, setup a very simple tooltip behaviour: disable when valid, enable otherwise. Set this to False for more complex behaviours. Defaults to None, meaning dependent on other options. When fn is None or fnSimple is False, default to True, with this the user has no way to control this. Otherwise, default to False.

  • tkWhen – Calculated Tk setting, based on the other parameters. See validation modes documentation.

class tkmilan.model.VState(label: str, value: vsT | None = None)#

Bases: Generic[vsT]

Hold validated state.

This is needed to make sure the received object is really a validated state, or just any regular state.

Parameters:
  • label – The label present on the widget.

  • value – The validated value. Can be None when invalid, see valid.

dict(*, dict_factory=<class 'dict'>)#

Get this information as a dictionary.

property valid: bool#

Is the validated value valid?

class tkmilan.model.VWhy(vstate: VState, why: Literal['key', 'focusin', 'focusout', 'forced', 'initial', 'self'], t: Literal[-1, 0, 1], widget: mixin.MixinWidget, tt: Optional[Tooltip])#

Bases: object

Validation runtime information.

There is no Python documentation, see Tk trace validation documentation.

Parameters:
  • vstate (VState) – The widget validated state.

  • why (Literal['key', 'focusin', 'focusout', 'forced', 'initial', 'self']) –

    Validation script substitution: validation condition (%V).

    See ValidateWhyT.

  • t (Literal[-1, 0, 1]) –

    Validation script substitution: action type (%d).

    See ValidateST.

  • widget (mixin.MixinWidget) – The widget being validated.

  • tt (Optional[Tooltip]) –

    The widget tooltip. Optional.

    When this is None, it means the automatic tooltip handling will run, and vice versa.

validation() bool | None#

Run the natural validation for this reason.

See mixin.MixinValidationSingle.setup_validation.

class tkmilan.model.WState(state: wsT | None, substate: wsST)#

Bases: Generic[wsT, wsST]

Hold wrapped state.

This is needed to mark state as being a product of a wrapped container.

dict(*, dict_factory=<class 'dict'>)#

Get this information as a dictionary.

state: wsT | None = <dataclasses._MISSING_TYPE object>#

The widget state.

This is the extra value being stored on the widget. Optional, if the variable already exists upstream.

substate: wsST = <dataclasses._MISSING_TYPE object>#

The wrapped state.

This is the original value being stored on the widget.

class tkmilan.model.WStateR(state: wsT | None, substate: wsST)#

Bases: WState

Reversed version of the WState state.

This is exactly the same as the other object, but marks the widget state as “reversed” compared to the regular version. What that means is widget-specific, usually only required for validation.

state: wsT | None = <dataclasses._MISSING_TYPE object>#

The widget state.

This is the extra value being stored on the widget. Optional, if the variable already exists upstream.

substate: wsST = <dataclasses._MISSING_TYPE object>#

The wrapped state.

This is the original value being stored on the widget.

class tkmilan.model.WStyle(_default: bool = False)#

Bases: object

Widget style object.

This is super class of all widget-specific style objects.

All subclass arguments should be optional, with a nice-looking default value.

Parameters:

_default (bool) – Does this represent a default value? When this is set (only for class __init__ definitions), the values can be safely overriden.

Note

Not to be confused with tkinter.ttk.Style objects.

class tkmilan.model.WidgetDynamicState(getter: Callable, setter: Callable, noneable: bool, container: bool = False)#

Bases: object

Hold the dynamic state for a widget.

See mixin.MixinState.

Parameters:
  • getter (Callable) – Function to retrieve the state

  • setter (Callable) – Function to change the state

  • noneable (bool) – Is this widget noneable? See tkmilan.mixin.MixinState.isNoneable.

  • container (bool) – Is this widget a container? Defaults to False.

class tkmilan.model.WidgetGeometry(x: int, y: int, w: int | None = None, h: int | None = None)#

Bases: object

Hold the geometry information for a widget.

See the wgeometry function to obtain this information from any widget.

Parameters:
  • x (int) – X coordinate for the widget’s topleft corner, relative to the root window

  • y (int) – Y coordinate for the widget’s topleft corner, relative to the root window

  • w (int | None) – Width of the widget. Optional, see also h and sized.

  • h (int | None) – Height of the widget. Optional, see also w and sized.

tk_geometry(*, sized: bool | None = None) str#

Convert the values into a “geometry string”.

This is mostly used on Tk functions.

tuple(*, tuple_factory=<class 'tuple'>)#

Get this information as a tuple.

property sized: bool#

Check if the object has size information

property wsize: PixelSize | None#

Get the corresponding widget size

class tkmilan.model.WidgetView(xview: Tuple[float, float] | None, yview: Tuple[float, float] | None)#

Bases: object

Hold the view information for a widget. This is important for scrollable widgets.

See the wview function to obtain this information from any widget.

There is no Python documentation, see Tk widget xview and widget yview documentation.

Parameters:
  • xview (Tuple[float, float] | None) – Tuple containing the start and end fractions of the width currently visible. Optional, None if the widget does not support scrolling on the X axis.

  • yview (Tuple[float, float] | None) – Tuple containing the start and end fractions of the height currently visible. Optional, None if the widget does not support scrolling on the Y axis.

classmethod fromwidget(widget: Widget | Tk) WidgetView | None#

Gather WidgetView information from a widget object.

When the wview function is not available on the widget itself, you can use this function.

Parameters:

widget (Widget | Tk) – The widget object to consider.

Returns:

Return a model.WidgetView object with the view information, if the widget supports scrolling in at least one axis. If the widget does not support scrolling, returns None.

Return type:

WidgetView | None

shown(x: float | None, y: float | None) bool | None#

Check if the given fraction position is visible.

Parameters:
  • x (float | None) – Fraction of width. Optional

  • y (float | None) – Fraction of height. Optional

Returns:

Return None if the widget does not support scrolling on the X or Y axes. Otherwise, return a bool representing if both x and y fractions are contained in xview/yview.

Return type:

bool | None

See also

See xshown or yshown for a single-axis version of this function.

xshown(x: float) bool | None#

Check if the given width fraction is visible.

Parameters:

x (float) – Fraction of width.

Returns:

Return None if the widget does not support scrolling on the X axis. Otherwise, return a bool representing if x is contained in xview.

Return type:

bool | None

yshown(y: float) bool | None#

Check if the given height fraction is visible.

Parameters:

y (float) – Fraction of height.

Returns:

Return None if the widget does not support scrolling on the Y axis. Otherwise, return a bool representing if y is contained in yview.

Return type:

bool | None

property deltax: float | None#

Calculate the visible width fraction.

Returns:

Return None if the widget does not support scrolling on the X axis. Otherwise return a float represening the visible width fraction.

property deltay: float | None#

Calculate the visible height fraction.

Returns:

Return None if the widget does not support scrolling on the Y axis. Otherwise return a float represening the visible height fraction.

property specced#

Check if this object is fully specced.

This indicates if scrolling on both widgets is supported.

class tkmilan.model.WindowState(fullscreen: bool | None)#

Bases: object

GUI State for entire windows.

This object tracks changes to attributes that apply entire windows, not individual widgets.

Parameters:

fullscreen (bool | None) – Show the window contents on the entire screen.

See also

This is used in RootWindow, as rgstate.

items()#

Workaround for dataclasses.asdict issue.

This is a problem-free version of:

return dataclasses.asdict(self).items()
tkmilan.model.Alignment_CP: CP] = {(-1, -1): CP.SW, (-1, 0): CP.S, (-1, 1): CP.SE, (0, -1): CP.W, (0, 0): CP.center, (0, 1): CP.E, (1, -1): CP.NW, (1, 0): CP.N, (1, 1): CP.NE}#

Conversion between numeric positioning and CP.

The numeric positioning is an encoding of vertical and horizontal positions relative to the center, in a RTL, top-to-bottom configuration.

tkmilan.model.CP_Compound: Mapping[CP | bool | None, str] = {CP.default: 'none', CP.N: 'bottom', CP.S: 'top', CP.E: 'left', CP.W: 'right', True: 'image', False: 'text', None: 'center'}#

The compound configuration setting.

This is the mapping between CP and the compound configuration string used in several locations.

Besides the cardinal points CP.N, CP.S, CP.E, CP.W, there are also special cases:

  • CP.default: Show only the image if given, otherwise show only label.

  • True: Show only the image

  • False: Show only the label

  • None: Show image and label, both centered

There is no Python documentation, see Tk compound documentation.

tkmilan.model.CP_S: Mapping[CP, Sticky] = {CP.N: Sticky(N=True, S=False, E=False, W=False), CP.S: Sticky(N=False, S=True, E=False, W=False), CP.E: Sticky(N=False, S=False, E=True, W=False), CP.W: Sticky(N=False, S=False, E=False, W=True), CP.NE: Sticky(N=True, S=False, E=True, W=False), CP.NW: Sticky(N=True, S=False, E=False, W=True), CP.SE: Sticky(N=False, S=True, E=True, W=False), CP.SW: Sticky(N=False, S=True, E=False, W=True), CP.center: Sticky(N=False, S=False, E=False, W=False)}#

The sticky configuration setting.

This is the mapping between CP and the corresponding Sticky object.

See Sticky, used in pgrid* family of functions.

tkmilan.model.CP_ScrollAnchor: Mapping[CP, Tuple[float, float]] = {CP.N: (-0.5, 0.0), CP.S: (-0.5, -1.0), CP.E: (-1.0, -0.5), CP.W: (0.0, -0.5), CP.NE: (-1.0, 0.0), CP.NW: (0.0, 0.0), CP.SE: (-1.0, -1.0), CP.SW: (0.0, -1.0), CP.center: (-0.5, -0.5)}#

The ScrolledWidget/Scrolled scroll anchor configuration setting.

The scroll function aligns the relative coordinates to the CP.NW corner, this includes the adjustments necessary to support all cardinal points.

See ScrolledWidget.scrollTo and Scrolled.scrollTo.

tkmilan.model.CSIZE = 4#

Pixel Coordinate Logging Size.

This is passed to %*d to format pixel coordinates.

4 is a good value, since it supports coordinates until 10000, that should be enough for most pratical screens.

This is a global value, should remain read-only.

tkmilan.model.GUI_STATES: Mapping[str, GuiState_Tk] = {'alternate': GuiState_Tk(string='alternate', invert=False), 'enabled': GuiState_Tk(string='disabled', invert=True), 'readonly': GuiState_Tk(string='readonly', invert=False), 'valid': GuiState_Tk(string='invalid', invert=True)}#

GuiState Tk metadata.

See GuiState_Tk.

tkmilan.model.GUI_STATES_common = ('enabled', 'valid')#

GuiState common to all widgets.

See GUI_STATES.

tkmilan.model.IMAGE_TYPES = {'gif': <class 'tkinter.PhotoImage'>, 'png': <class 'tkinter.PhotoImage'>}#

Supported image types, and corresponding loaders.

See ImageCache.

tkmilan.model.Justification_CP: Mapping[Justification, CP] = {Justification.NoJustify: CP.default, Justification.Left: CP.W, Justification.Center: CP.center, Justification.Right: CP.E}#

Conversion between Justification and CP objects.

This is useful to convert between types, since some widgets have weird interactions between justify and anchor settings.

tkmilan.model.NotebookTabStateT#

The supported NotebookTab state types.

Their meanings are as follows:

  • normal: A regular tab

  • disabled: The tab is shown, but disabled. This means it cannot be

    selected, not even programatically.

  • hidden: The tab is not shown. If you show it (using Notebook.wselect),

    it goes back to normal state.

There is no Python documentation, see Tk notebook tab state type documentation.

alias of Literal[‘normal’, ‘disabled’, ‘hidden’]

tkmilan.model.TraceModeT#

The supported operations to watch for a trace.

There is no Python documentation, see Tcl trace variable documentation.

alias of Literal[‘read’, ‘write’, ‘unset’]

tkmilan.model.ValidateST#

The supported validation action types.

Their meanings are as follows:

  • -1: Post-Validation. The most common usage.

  • 0: Pre-Validation: Delete

  • 1: Pre-Validation: Insert

There is no Python documentation, see Tk trace validation action type documentation.

alias of Literal[-1, 0, 1]

tkmilan.model.ValidateWhenT#

The supported validation modes, to be set when arguments.

There is no Python documentation, see Tk trace validation modes documentation.

alias of Literal[‘focus’, ‘focusin’, ‘focusout’, ‘key’, ‘all’, ‘none’]

tkmilan.model.ValidateWhyT#

The supported validation modes, to be given for why arguments.

Includes native and synthetic types.

There is no Python documentation, see Tk trace validation return mode documentation.

alias of Literal[‘key’, ‘focusin’, ‘focusout’, ‘forced’, ‘initial’, ‘self’]