tclapp tcltk

Correctly using source and exec in TclApp


When I wrap my Tcl application with TclApp, I get errors when my code tries to source or exec another wrapped tcl file.


This is usually a problem with relative paths within TclApp's vfs. Here is an example for how to work around this:

package require Tk

set ::DIR [file dirname [info script]]

button .b -text 'Kill!' -command {source $::DIR/sourced.tcl }

pack .b

This script is setting $::DIR to be the basepath of the current
script. You can use this value to source or exec other scripts either when
wrapped or running as a script, regardless of what CWD is.