I'm having trouble understanding how the wish
program works, to make a good old "Hello, World".
For those who do not know what wish
is, it is a TCL interpreter ready to make graphical interfaces in TK. You program in TCL, create your widgets and position them on the screen.
For example, to make a button that prints Hello World
on the console (with shebang and all):
#!/usr/bin/env wish
button .submit -text "Click Me" -command { puts "\nHello World" }
pack .submit
In the first line, we create a button identified as .submit
, saying Click Me
which, when clicked, executes the TCL command to print on the Hello World
console.
Next, we have the widget named .submit
in the package of things on the screen.
See working:
Sofar,I'vebeenabletomakea"Hello, World" on the console, but not on the screen. I would like to change the text of a label, or even the button itself, to "Hello, World". I tried changing the click command to
{ puts "\nHello World"; button .submit -text "Hello" }
however ... I am greeted with the following message:
Error, window name "submit" already exists in parent
that in free translation would be:
Error, "submit" window name already exists in parent
That is, simply calling button .submit
tries to again a button called .submit
I got a label on the screen with a slight variation:
{ puts "\nHello World"; label .teste -text "Hello"; pack .teste }
But clicking the button again will cause the same error that the component already exists on the screen.
So, my question is:
- How to change the test of a widget already placed on the screen?
- Or should I remove and reinsert the component with the changes?