tk_popup

Summary

tk_popup is a Tk command to post a popup menu.

Documentation

reference manual

See Also

popup
Pragmatic use of Pernicious Popups
how to deal with quirky behaviour on different platforms
menu
tk_optionMenu

Synopsis

tk_popup menu x y ?entry?

DESCRIPTION

This procedure posts a menu at a given position on the screen and configures Tk so that the menu and its cascaded children can be traversed with the mouse or the keyboard. Menu is the name of a menu widget and x and y are the root coordinates at which to display the menu. If entry is omitted or an empty string, the menu's upper left corner is positioned at the given point. Otherwise entry gives the index of an entry in menu and the menu will be positioned so that the entry is positioned over the given point.

MHo 2015-06-29: I don't understand why the popup menu don't get keyboard focus if the popup is used "standalone", e.g.:

wm withdraw .
menu .p -tearoff 0
.p add command -label "one" -command {puts cmd1}
.p add command -label "two" -command {puts cmd2}
tk_popup .p {*}[winfo pointerxy .] 0
tkwait window .p

This shows the menu, but the keyboard focus is elsewhere. Only after right clicking into the popup menu, the widget gains focus. What's the difference with this example?

# Create a menu
set m [menu .popupMenu]
$m add command -label "Example 1" -command bell
$m add command -label "Example 2" -command bell

# Create something to attach it to
pack [label .l -text "Click me!"]

# Arrange for the menu to pop up when the label is clicked
bind .l <1> {tk_popup .popupMenu %X %Y}

MHo Meanwhile I found the solution by myself; this works as expected, although the first menu entry isn't always selected.......:

wm withdraw .
menu .p -tearoff 0
update ; # <===========================================================
.p add command -label "one" -command {puts cmd1}
.p add command -label "two" -command {puts cmd2}
tk_popup .p {*}[winfo pointerxy .] 0

MHo Whatever I bind to .p, it does not work....why?