Given this class:
oo::class create App {
# ...
variable ShowState
}
And this method:
oo::define App method make_controls {} {
# ...
ttk::radiobutton .controlsFrame.showFrame.asIsRadio \
-text "Show as-is" -value asis -variable ShowState
set ShowState asis
The variable given to the radio button and the instance variable
are _different_.
I tried these variations, all of which gave errors:
-variable [my ShowState]
-variable [my $ShowState]
-variable [self ShowState]
-variable [self $ShowState]
For now I'm using a global variable ::ShowState
but I'd really like it to be an instance variable -
if it can be done?
Given this class:
oo::class create App {
# ...
variable ShowState
}
And this method:
oo::define App method make_controls {} {
# ...
ttk::radiobutton .controlsFrame.showFrame.asIsRadio \
-text "Show as-is" -value asis -variable ShowState
set ShowState asis
The variable given to the radio button and the instance variable are_different_.
On 11/07/2025 11:55, Mark Summerfield wrote:
Given this class:
oo::class create App {
# ...
variable ShowState
}
And this method:
oo::define App method make_controls {} {
# ...
ttk::radiobutton .controlsFrame.showFrame.asIsRadio \
-text "Show as-is" -value asis -variable ShowState
set ShowState asis
The variable given to the radio button and the instance variable
are_different_.
ttk::radiobutton .controlsFrame.showFrame.asIsRadio \
-text "Show as-is" -value asis -variable [my varname ShowState]
Schelte.
That silently didn't work.
Another way to get the fully qualified name of the variable is
[namespace which -variable ShowState]. But as that produces the same
result, it also won't work until you fix that other bug.
On Fri, 11 Jul 2025 21:12:08 +0200
Schelte <nospam@wanadoo.nl> wrote:
...
Another way to get the fully qualified name of the variable is
[namespace which -variable ShowState]. But as that produces the same
result, it also won't work until you fix that other bug.
Adding to what Schelte correctly pointed out, these are your options:
* [my varname somevar]: This works inside TclOO objects, and works for scalar
variables, arrays and array elements.
* [namespace which -variable somevar]: This works inside TclOO objects and
namespaces. Works for scalar variables and arrays, but not for array
elements. See Tcl bug#472113 . If you need an array element, use
[namespace which -variable somearray](element).
* last but not least, [namespace current]::somevar works if somevar is
a variable in the current namespace, including the namespace of any TclOO
object, and works for scalar, array and array elements.
Regards
On 11/07/2025 17:21, Mark Summerfield wrote:
That silently didn't work.
Then you have a bug somewhere in the code you didn't show, because [my varname ShowState] correctly produces the fully qualified name of the instance variable.
Another way to get the fully qualified name of the variable is
[namespace which -variable ShowState]. But as that produces the same
result, it also won't work until you fix that other bug.
Schelte.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 163:56:39 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
9,208 files (2,741M bytes) |
Messages: | 2,411,516 |