tk_dialog(3tk)

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

✨ tk_dialog β€” bestie, we're making a modal dialog and WAITING πŸ’…

okay so real talk, this one lives in tk_dialog(3tk), part of the Tk Built-In Commands squad, and it's about to be your whole personality for like, five minutes while a box sits there being dramatic. let's go πŸŽ€


✨ SYNOPSIS ✨

tk_dialog window title text bitmap default string string ...

that's it. that's the whole vibe check. window, then a lil parade of arguments. πŸ¦‹


✨ DESCRIPTION ✨

so, this procedure is part of the Tk script library, and ngl it's largely deprecated by tk_messageBox. like, it still works, but it's giving "your older cousin who still uses Facebook." anyway. its arguments describe a dialog box, and here's the breakdown, one bestie at a time:

  • window β€” name of the top-level window to use for the dialog. πŸͺŸ and heads up: any existing window by this name is destroyed. gone. no cap. it doesn't ask, it just does.
  • title β€” the text that shows up in the window manager's title bar for the dialog. that's the little strip at the top, bestie. πŸ‘‘
  • text β€” the message that appears in the top portion of the dialog box. this is the part everyone actually reads.
  • bitmap β€” if this is non-empty, it specifies a bitmap (in a form suitable for Tk_GetBitmap) to display in the top portion of the dialog, to the left of the text. if it's an empty string, then no bitmap shows up in the dialog. simple as that. 🎨
  • default β€” if this is an integer greater than or equal to zero, then it gives the index of the button that's gonna be the default button for the dialog (0 for the leftmost button, and so on). if it's negative, or an empty string, then there is no default button at all. πŸ™ˆ
  • string β€” there's one button for each of these arguments. each string specifies the text to display in a button, in order from left to right. so yeah, you can have as many as you want, just keep listing them. πŸ”₯

🌸 so what happens next 🌸

after creating the dialog box, tk_dialog waits for the user to pick one of the buttons β€” either by clicking on it with the mouse, or by typing return to invoke the default button (if there is one, iykyk). then it returns the index of the selected button: 0 for the leftmost button, 1 for the button next to it, and so on. count from the left, babe, always. πŸ’…

and if the dialog's window gets destroyed before the user selects one of the buttons, then -1 is returned. yeah. it's giving abandoned. 😭

while it's waiting for the user to respond, tk_dialog sets a local grab. this prevents the user from interacting with the application in any way except to invoke the dialog box. so like, the whole app is on pause until somebody picks a button. main character energy fr fr β€” the dialog IS the moment. ⭐

✨ EXAMPLE ✨

set reply [tk_dialog .foo "The Title" "Do you want to say yes?" \
        questhead 0 Yes No "I'm not sure"]

look at her go 🫢 three buttons, questhead bitmap, 0 is the default so Yes is the one that lights up. iconic.


✨ SEE ALSO ✨


✨ KEYWORDS ✨

bitmap, dialog, modal πŸ’–


k bye bestie, this page is from the Tk 4.1 era and belongs to the tk_dialog(3tk) manual β€” oldie but a goodie, stay slay, drink water, close your dialogs properly βœ¨πŸŽ€πŸ’œ

πŸ“¦ where this page comes from