Navigation Logo 11.5  Cleaning Up the Root Window Navigation Logo

 

 

Learning Tk seems to be easier when you run Tk interactively because then you can type commands and see their effects. Unfortunately, cleaning up the messes you make is something you learn how to do at a later time.

One way to clean up your messes is to restart wish?? a lot. Another is to load Script S11.5a and run the cleanTk procedure.

Script S11.5a: The cleanTk procedure.
## cleanTk, Script 11.5a of "Tcl/Tk For Programmers"
proc cleanTk {{Master .}}  {

### read all comments before using

if {$Master=="."} {

### get rid of all widgets other than . with their bindings

eval destroy [winfo children .]

### get rid of any bindings to .

foreach E [bind .] { bind . $E {} }

### destroy all images

eval image delete [image names]

### reset root window's title

global argv0

wm title . $argv0

### bring root window back to top

raise .

### restore root's automatic window sizing

wm geometry . {}

pack propagate . 1

} else {

### get rid of $Master and it's children with all their bindings

destroy $Master

}

### cleanTk does not restore Tcl things such as variables and procedures

### to their original state; it also misses a few Tk things such as

### bindings to new nonwidget tags and colors of the root window }

 

 

[Sample TK Application]
Author's Home Page
Navigation Logo [Book's Cover]
Order from Amazon.