tk_popup(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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.
  • x and y β€” 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 entry is 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, entry gives the index of an entry in menu, 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. πŸ’…

πŸ”₯ 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