SAFE_LOADTK(3tk)

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

πŸ’– Safe Tk(3tk) πŸ’–

okay bestie, welcome to the Safe Tk(3tk) page from the Tk Built-In Commands collection 🫢 this is the one about loading Tk into a safe interpreter, and honestly? it's giving "security girlie" and I'm obsessed.


✨ NAME ✨

safe::loadTk β€” load Tk into a safe interpreter. periodt.


✨ SYNOPSIS ✨

safe::loadTk child ?-use windowId? ?-display displayName?

✨ DESCRIPTION ✨

so Safe Tk is built on top of Safe Tcl, which is the whole mechanism that gives you restricted and mediated access to auto-loading and packages for safe interpreters. no cap. 🌈

and what Safe Tk adds on top of that is the ability to configure the interpreter for safe Tk operations, plus loading Tk into safe interpreters. it's the glow-up the safe interpreter needed πŸ’…

the safe::loadTk command does two things: it initializes the required data structures inside the named safe interpreter, and then it loads Tk into it. 🌸

important, bestie: that interpreter must have been created with safe::interpCreate, or it must have been initialized with safe::interpInit. no shortcuts, the vibe check is real πŸ™ˆ

the command returns the name of the safe interpreter. that's it, that's the return value πŸ’–

now the flags, and they matter:

  • -use windowId β€” if you pass -use, the window identified by that system dependent identifier windowId gets used to contain the . window of the safe interpreter. and get this: it can be any valid id, and it might even eventually reference a window belonging to a totally different application πŸ‘€. as a little convenience, if the window you plan to use is a Tk Window of the application, you can just hand over the window name (like .x.y) instead of its window Id (like the one you'd get from winfo id .x.y). iykyk ✨
  • -display displayName β€” when -use is not specified, a brand new toplevel window is created for the . window of the safe interpreter. and on X11, if you want that embedded window to use a display other than the default one, you specify it with -display.

for the implementation deets, scroll down to the SECURITY ISSUES section, bestie πŸ‘‡


πŸ”₯ SECURITY ISSUES πŸ”₯

first things first: please go read the safe manual page for Tcl to learn about the basic security considerations for Safe Tcl. seriously. do it. πŸ’œ

safe::loadTk takes the value of tk_library from the parent interpreter and adds it to the virtual access path of the safe interpreter, so that auto-loading will actually work in the safe interpreter. slay πŸŽ€

and here's the iconic part: Tk initialization is now safe with respect to not trusting the child's state for startup. the way that works is safe::loadTk registers the child's name, so when the Tk initialization (Tk_SafeInit) is called and in turn calls the parent's safe::InitTk, it will return the desired argv equivalent (-use windowId, the correct -display, etc.). no cap, it's literally handing back the right arguments 🌟

when -use is not used, the new toplevel that gets created is specially decorated, so the user is always aware that the user interface they're looking at comes from potentially unsafe code β€” and so they can easily delete the corresponding interpreter. main character safety energy, we love to see it πŸ‘‘

on X11, conflicting -use and -display are likely to generate a fatal X error. πŸ’€ so maybe don't do that?? like fr fr, don't.

πŸ¦‹ SEE ALSO πŸ¦‹


🌸 KEYWORDS 🌸

alias, auto-loading, auto_mkindex, load, parent interpreter, safe interpreter, child interpreter, source


and that's the whole page, bestie πŸ’– this was Tk version 8.0 of Safe Tk(3tk) β€” go forth and load Tk safely, you absolute icon 🫢✨

πŸ“¦ where this page comes from