Skip to content

After

This capability documents one focused aspect of the widget interface (Tk/Tcl-style behavior + bootstack extensions).

Note: You typically won’t use bootstack.core.capabilities.after directly. This page describes the behavior that widgets expose.

Scheduling helpers (after).

Tk’s after family lets you schedule callbacks to run later on the Tk event loop.

Common uses
  • Debounce user input (schedule a callback and cancel previous ones).
  • Run periodic UI updates (schedule, then reschedule from inside the callback).
  • Defer work until the UI is idle (after_idle) so layout/paint can complete.
Notes
  • Callbacks run on the Tk thread/event loop. If you have long-running work, run it off-thread/process and schedule UI updates back onto Tk using after.
  • after returns an identifier that can be canceled with after_cancel.

after

after(
    ms: int,
    func: Callable[..., Any] | None = None,
    *args: Any,
) -> str

Schedule a callback to run after a delay.

Parameters:

Name Type Description Default
ms int

Delay in milliseconds.

required
func Callable[..., Any] | None

Callback to run. If omitted/None, Tk blocks for ms milliseconds while still processing events (use sparingly).

None
*args Any

Arguments to pass to func when it is called.

()

Returns:

Type Description
str

An identifier that can be used with after_cancel.

after_idle

after_idle(func: Callable[..., Any], *args: Any) -> str

Schedule a callback to run when the event loop is idle.

Idle callbacks run after Tk has finished processing the current batch of events and pending UI work.

Parameters:

Name Type Description Default
func Callable[..., Any]

Callback to run.

required
*args Any

Arguments to pass to func when it is called.

()

Returns:

Type Description
str

An identifier that can be used with after_cancel.

after_cancel

after_cancel(id: str) -> None

Cancel a scheduled callback.

Parameters:

Name Type Description Default
id str

The identifier returned by after or after_idle.

required

after_repeat

after_repeat(
    ms: int, func: Callable[..., Any], *args: Any
) -> Callable[[], None]

Call func repeatedly every ms milliseconds.

This helper schedules func and then automatically reschedules it after each run. It returns a cancel() function you can call to stop repetition.

Parameters:

Name Type Description Default
ms int

Interval in milliseconds.

required
func Callable[..., Any]

Callback to run each interval.

required
*args Any

Arguments to pass to func.

()

Returns:

Type Description
Callable[[], None]

A cancel() callable. Call it to stop the repeating schedule.

Examples:

>>> cancel = widget.after_repeat(250, tick)
>>> cancel()