beetlebug▾
/

tk_popup

Shows a menu as a popup at a point of the screen.

tk_popup MENU X Y ?ENTRY?

Description

Posts the menu widget MENU with its top left corner at X Y, in the coordinates of the screen, as the menu of a right click. The script of the -postcommand of the menu runs first. A click on an entry invokes it and closes the menu, and a click outside the menu closes it. The command gives at once, and the menu stays open.

A binding of <Button-3> usually calls it with the coordinates of the pointer, %X and %Y. On a touch screen a long press is a <Button-3> event, so the same binding opens the menu.

With ENTRY, ztk passes the entry to the post command of the menu.

On Windows and macOS, the menu is the popup menu of the platform. The other backends draw the menu with the widgets of ztk.

Arguments

ArgumentTypeDefaultDescription
MENUwindowrequiredThe path of a menu widget.
XintegerrequiredThe left edge of the menu, in pixels from the left of the screen.
YintegerrequiredThe top edge of the menu, in pixels from the top of the screen.
ENTRYindexnoneAn index of an entry of the menu, for the place of the menu in Tk.

Returns

An empty string.

Examples

% menu .m -tearoff 0 -postcommand {set ::opened 1}
> .m add command -label Copy
> .m add command -label Paste
> tk_popup .m 100 80
> .m unpost
> set ::opened
1

# The usual binding of a menu of a right click.
% frame .area -width 200 -height 100
> bind .area <Button-3> {tk_popup .m %X %Y}
> bind .area <Button-3>
tk_popup .m %X %Y

Errors

% tk_popup
wrong # args: should be "tk_popup menu x y ?entry?"
-errorcode TCL WRONGARGS

% tk_popup .nope 10 10
invalid command name ".nope"
-errorcode TCL LOOKUP COMMAND .nope

% button .b
> tk_popup .b 10 10
bad option "post": must be cget, configure, flash, or invoke
-errorcode TCL LOOKUP INDEX option post

% menu .m2
> tk_popup .m2 10 y
expected integer but got "y"
-errorcode TCL VALUE NUMBER

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1