getstring(3tk)

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

πŸ’– getstring β€” a whole string dialog, bestie πŸ’–

okay so this is the getstring page from the tklib manual, section 3tk. it's giving "tiny Tcl package that pops up a little box and asks u for a string." slay. let's get into it ✨


✨ NAME ✨

getstring β€” a string dialog πŸŽ€


🌸 SYNOPSIS 🌸

package require Tcl 8.4

package require getstring ?0.1?

::getstring::tk_getString pathName variable text ?options?

so first u need Tcl 8.4 or better (no cap, it's required fr), then u pull in the getstring package itself β€” version 0.1 is optional in that ?0.1? way, iykyk πŸ’… β€” and then the main character: ::getstring::tk_getString.


πŸ¦‹ DESCRIPTION πŸ¦‹

this package hands u a dialog made of three little things: an Entry, an OK button, and a Cancel button. that's the whole vibe. simple, iconic, does exactly what it says 🫢

πŸ’œ ::getstring::tk_getString pathName variable text ?options?

this makes a dialog that prompts the user with text, asking them to type in a string. whatever they typed into the entry gets dropped into variable the moment the dialog closes. and the command itself returns a boolean β€” it tells u whether the user hit OK or not. true = they said yes bestie, false = they dipped 😭

about the placement, and this part is important: if u don't pass -geometry, the dialog gets centered inside its parent toplevel β€” unless its parent is ., in which case it gets centered on the screen instead. little detail, big difference 🌈

here are the options, all of them, don't skip:

  • -title β€” the title option. the manpage lists it and then just… moves on πŸ™ˆ so that's what we're working with, bestie.
  • -allowempty β€” a boolean argument saying whether the dialog should accept an empty entry. so like, can they submit nothing? u decide.
  • -entryoptions β€” just passes its arguments straight through to the entry widget. this is genuinely valuable, ngl, because it lets u do extra validation using the Entry widget's validation hooks πŸ”₯
  • -geometry β€” specifies the geometry of the window ✨

⭐ EXAMPLE ⭐

package require getstring
namespace import getstring::*

if {[tk_getString .gs text "Feed me a string please:"]} {
    puts "user entered: $text"
}

see how it works? if the boolean comes back true, u print what they typed. if they cancelled, u don't. main character energy fr πŸ’…


πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

ok so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. that's just how it is, no shame.

please report them in the category getstring of the Tklib Trackers at [http://core.tcl.tk/tklib/reportlist].

and if u have ideas for enhancements β€” for either the package and/or the documentation β€” report those too, bestie. we wanna hear them 🫢


πŸ‘‘ KEYWORDS πŸ‘‘

dialog, entry, string 🌸


and that's the whole page, no crumbs left. this was tklib version 0.1, page getstring(3tk) β€” go forth and prompt, u got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from