7
I’m having trouble understanding how the program works wish
, to make a good old "Hello, World".
For those who don’t know what the wish
, 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
, with the saying Click Me
which, when clicked, executes the TCL command to print on the console Hello World
.
Then we sent for the widget so-called .submit
in the pack of screen things.
See working:
So far, I was able to do a "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 to change the click command to
{ puts "\nHello World"; button .submit -text "Hello" }
but... I am greeted with the following message:
Error, window name "Submit" already exists in Parent
which in free translation would be:
Error, window name "Submit" already exists in parent
I mean, just call the button .submit
tries to create again a button called .submit
I managed to put 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 I should remove and reinsert the component with the changes?
Which test do you want to change? If you just change the text of the button, you can use the command
configure
with the property-text
. Example:{ .submit configure -text "Novo Texto" }
– Gomiero
@Gomiero didn’t even know he could do the
.submit configure
. That comment of yours would be a good enough answer for me. Waiting for you to turn the comment into a response so you can accept and share the knowledge– Jefferson Quesado