TclOO Widget Class with Garbage Collection (wob)

The package "wob" adds a TclOO class that creates a Tk window in a separate interpreter.

Traces and Tk button binds are used to link the Tk window, object, and interpreter, so that if you destroy the object, it destroys the interpreter and the window, and if you close the window, it destroys the object and interpreter.

For example, the following script creates an object with a separate interpreter, and gets the results.

package require tin
tin import wob
set widget [widget new]
$widget eval {
wm minsize . 250 50
label .label -text "Choose analysis type:"
tk_optionMenu .options AnalysisType "" Pushover Dynamic
pack .label -side top -fill x
pack .options -side bottom -fill x
vwait AnalysisType
}
puts [$widget get AnalysisType]
$widget destroy

You can also create variable links between the widget interpreter and the parent interpreter:

package require tin
tin import wob
set widget [widget new]
$widget upvar foo x(1)
$widget upvar bar x(2)
set foo "hello "
set bar "world"
puts [$widget eval {string cat $x(1) $x(2)}]; # prints "hello world"

GitHub project: https://github.com/ambaker1/wob

It is also a Tin package, so if you have Tin, you can install and use it on the fly.