Unperson Monday November 23 2026, 12:32 am
We want to place a variable at the label. We did this way:
-label ${::label.of.directory1}The label is defined in the following code:
proc Read.label.of.directory1 {} {
# STEP 1 — LOCATE Preferences.txt
set preferencesFile [file join [file dirname $::icon_dir] Preferences Preferences.txt]
# STEP 2 — INITIALIZE LABEL VARIABLE
set ::label.of.directory1 ""
# STEP 3 — READ LABEL OF DIRECTORY 1
set labelResult [readMarkedBlock $preferencesFile "Label of directory 1"]
if {[lindex $labelResult 0]} {
set ::label.of.directory1 [string trim [lindex $labelResult 1]]
}
return}
The program does not recognize the variable.
We have been trying all sorts of things for a few hours but nothing works. (I am talking about the label above command in the menu)
We've been putting variables for preferences all over the place and this is really the only problem we had with them.
Any good Samaritan around to help us?
TWu - 2026-11-23 08:29:40
The -label option (normally in Tk it is named -text) is for set one string directly.
This can be done via a variable reference too at run-time (substitution).
Changing the variable afterwards is not recognized at all!
For this the -textvariable option exists, where Tk/ttk do a trace on the change of variable's content.
Mostly the scope is global or You need to use a full-qualified variable-name - not a reference!
Alternatively You can trace Yourself the variable or bind to a configure event, reset the content on content change.
Hope this explanation helps You further.
Unperson 2026-11-23, 8h 01 am
Thanks Tommy!
I checked how the other values were done based on Preferences and this is what I got:
# Retrieve the preferences saved font family set.preferences2.values.font.family
And below ChatGPT would put the little procedure that would result in defining the variable.
I don't why he changed that mechanism.
I'll try the old mechanism and I should get better results.
Thanks again!
ONE HOUR LATER: A super TCL programmer can show me otherwise but my conclusion is that you cannot insert a variable in a TCL-TK menu.
Tommy, I am not a programmer. You are. So please deliver the code to be inserted (and not vague instructions) and I can try it.
Thanks!