tk_popup(3tk)
π tk_popup β bestie, it's literally "Post a popup menu" π
okay so picture this: you're out here in Tk land, manual page tk_popup(3tk), and you just want a menu to appear under somebody's cursor like the main character it is. That's this. That's the whole vibe. Let's go β¨
β¨ SYNOPSIS β¨
tk_popup menu x y ?entry?
Three little args and one optional bestie, no big deal. π
πΈ DESCRIPTION πΈ
So what this procedure actually does: it posts a menu at a given position on the screen, and then it configures Tk so that the menu β and its cascaded children β can be traversed with the mouse or the keyboard. Yes, both. Versatile queen. π
menuβ the name of a menu widget. That's your girl. That's who's coming to the party.xandyβ the root coordinates at which to display the menu. Root coordinates, bestie, not relative to some widget, don't play yourself.entryβ optional. And this one is lowkey the plot twist:- If
entryis omitted or is an empty string, then the menu's upper left corner gets positioned at the given point. Chill. Simple. Corner lands on the dot. π - Otherwise,
entrygives the index of an entry inmenu, and the menu gets positioned so that that entry is positioned over the given point. So like, the point lands on the entry, not the corner. Sneaky. Iconic. π
- If
π₯ EXAMPLE π₯
How to attach a simple popup menu to a widget. Look at her go:
# 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 <Button-1> {tk_popup .popupMenu %X %Y}
not me reading that and immediately wanting to click the label π the %X and %Y are handing you the root coords right there in the bind, so tk_popup gets exactly what it asked for. no cap. π«Ά
π¦ SEE ALSO π¦
go read those next, they're all in the same friend group fr fr π
β KEYWORDS β
menu, popup
real talk, no drama here β this one's all joy, just post your menu and live your truth π
and that's the whole page, bestie π this was Tk 4.0, dated tk_popup(3tk) β thanks for coming to my TED talk, now go pop a menu and slay β¨ππ
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms