ContextMenu
Public ContextMenu โ dispatches to a platform-appropriate backend.
On macOS this materializes as a native tk.Menu (NSMenu) so popups
integrate with the system, dodging the key-window/activation issues
that affect a reused overrideredirect Toplevel on Aqua. On Windows
and Linux it uses the themed Toplevel-backed implementation so
bootstyle, density, and rich item types apply consistently.
The public API is identical across backends. Consumers should not
rely on item() returning a Tk widget โ on the native backend it
returns the original spec dict, since no per-item widget exists.
__init__
__init__(
master: Master = None,
minwidth: int = 150,
width: int = None,
minheight: int = None,
height: int = None,
target: Misc = _TARGET_DEFAULT,
anchor: str = "nw",
attach: str = "se",
offset: tuple[int, int] = None,
hide_on_outside_click: bool = True,
items: list[ContextMenuItem] = None,
density: str = "default",
trigger: str | None = "right-click",
)
Create a ContextMenu.
Args mirror the underlying backend; trigger is a dispatcher-level
convenience that auto-binds the menu to target's click event so
callers don't have to wire a bind('<Button-3>', show_at) handler
themselves. Set trigger=None (or 'manual') to opt out and
manage activation in caller code (e.g. when the menu is built lazily).
target defaults to master when omitted, since the menu is
usually attached to the same widget that owns it. Pass target=None
explicitly to opt out of positioning/auto-binding (e.g. when calling
show(position=(x, y)) with cursor-driven coordinates instead).
Trigger values
'right-click'(default): portable right-click viabootstack.runtime.utility.bind_right_clickโ<Button-3>on Win/Linux plus<Button-2>and<Control-Button-1>on Aqua.'click'/'left-click':<Button-1>.'double-click':<Double-Button-1>.'shift-click':<Shift-Button-1>.'ctrl-click'/'control-click':<Control-Button-1>(note that on Aqua this is the same as Ctrl+click for context menus, since macOS uses Ctrl+click as a context-menu gesture).Noneor'manual': no auto-binding.