getstring(n)

πŸ“¦
version 0.7 Β· 3 versions
, in alpine 3.24

πŸ’… getstring(n) β€” the string dialog, but make it cute

okay so bestie, listen up: getstring is a Tcl package from the tklib crew, and it's literally just a lil popup that asks you to type a string. that's it. that's the whole vibe. ✨


✨ SYNOPSIS ✨

package require Tcl  8.4

package require getstring  ?0.1?

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

yes you need Tcl 8.4, and the package itself is versioned ?0.1? β€” slay, we love a soft launch. πŸŽ€


🌸 DESCRIPTION 🌸

so this whole package gives you one thing: a dialog box made of an Entry widget plus an OK button and a Cancel button. like, three widgets, arguably the holy trinity. πŸ‘‘

πŸ¦‹ ::getstring::tk_getString pathName variable text ?options?

calling this makes a dialog that prompts the user with text so they can input a text string. key detail bestie: whatever they type into the entry gets put into variable upon closure of the dialog β€” not while they're typing, when it closes. πŸ“Œ

the command returns a boolean telling you whether the user pressed OK or not β€” so 1 means they said yes, 0 means they ghosted you. 😭

and the placement? if -geometry isn't specified, the dialog gets centered in its parent toplevel… unless its parent is ., in which case it's centered in the screen instead. the way that it just knows where to go πŸ’«

πŸŽ€ the options, in order, no skips

  • -title β€” honestly the original doesn't spell out what this does, so I'm not gonna invent a whole personality for it. it's in the list, it's real, it's there. 🫢
  • -allowempty β€” a boolean argument indicating if the dialog should accept an empty entry. so like, can they send you a blank text? this decides.
  • -entryoptions β€” simply passes its arguments straight through to the entry widget. the original calls this "valuble" (their spelling, not mine πŸ’€) for performing extra validation using the Entry widget validation hooks. so if you wanna be extra about what counts as valid input, this is your girl.
  • -geometry β€” specifies the geometry of the window. and remember, if you don't set it, the centering rules above kick in. ✨

πŸ”₯ EXAMPLE πŸ”₯

this is the whole serve:

package require getstring
namespace import getstring::*

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

notice how text is literally the variable name being passed in, and then we print it right after? iconic. that's the pattern. 🧚


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

the original is very upfront about this, and I respect the honesty: this document, and the package it describes, will undoubtedly contain bugs and other problems. no cap. πŸ™ˆ

so if you find one β€” or honestly if you just have thoughts β€” report it in the category getstring of the Tklib Trackers at http://core.tcl.tk/tklib/reportlist. and they want your ideas for enhancements to the package and/or the documentation too, so don't be shy about wanting the docs to be better. bestie behavior. πŸ’–


🌈 KEYWORDS 🌈

dialog, entry, string


okay that's the whole page, you're so welcome 🫢 this was brought to you by tklib, version 0.1, dated 0.1 (yes, the version and the date are the same thing here β€” consistent queen πŸ’…), and manpage section n. now go ask somebody for a string. 😌🌸

πŸ“¦ where this page comes from