Re: Some newbie questions
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Some newbie questions

From: Schelte Bron <nospam@wanadoo.nl>
Date: Sat Jul 30 2005 - 21:51:02 CEST

"simonbachmann at bluewin dot ch" <"simonbachmann at bluewin dot
ch"> wrote:
> OK, but what if my script is in a file? source the file(s) again
> doesn't work if the script contains commands that create widgets.
> In other words, if in your example the proc 'abc' would contain as
> an example the command 'button .b -text "Hello"', and then change
> the command to 'button .b -text "Bye"' re-executing the proc,
> would give an error: "a window named .b already exists".

I think the easiest way is to withdraw the main window and create
your own toplevel that will act as the main window. Before creating
any toplevel, first destroy it. The destroy command will not
complain if the widget doesn't exist.

# Hide the real main window
wm withdraw .
# Create a replacement main window
destroy .main
toplevel .main
# Exit the application when the window is closed by the user
wm protocol .main WM_DELETE_WINDOW exit

This code can safely be sourced repeatedly.

You also have to take care with renaming built-in commands and
variable traces. But those things are not done that much by
newbies, so those topics can wait till later.

Schelte

-- 
set Reply-To [string map {nospam schelte} $header(From)]
Received on Thu Sep 29 14:28:04 2005