http://qs321.pair.com?node_id=1233542


in reply to Tcl::Tk exit

I rediscovered this issue in Tcl::pTk; see RT #128654.

The simple explanation is that Perl/Tk redefines exit (see Mastering Perl/Tk §1.4.1 "exit Versus destroy"), while Tcl::Tk and Tcl::pTk do not. I do not know the details of why using exit in Tcl::(p)Tk causes errors; maybe Perl/Tk's exit implementation offers more insight.

The working alternative is to use destroy, and as tybalt89's answer points out, it allows code appearing after MainLoop and any other cleanup code to run, unlike exit.

Even though -command => \&exit and -command => sub { exit } are documented and common idioms in Perl/Tk, I would not be surprised if Tcl::Tk chooses to not support these, given the available alternative; and even if supporting these is desirable for Tcl::pTk, I'm not sure whether that can or will ever get implemented. I suggest following the RT ticket in case of any updates.