Hello out there,
currently Tk accepts only _gobal_ variables for widgets which set a
value. I always wondered why it doesn't also accept a fully namespaced variable, too.
In Tcl 8 a syntax like
-var ::ns::someVar
is not illegal: it just doesn't have any effect
Helmut Giese <hgiese@ratiosoft.com> wrote:
Hello out there,
currently Tk accepts only _gobal_ variables for widgets which set a
value. I always wondered why it doesn't also accept a fully namespaced
variable, too.
Unless something has changed in 9, Tk has always accepted fully
qualified namespaced variables for Tk widget variables.
I.e.:
$ rlwrap wish
% namespace eval ns {
variable someVar ""
}
% puts $::ns::someVar
% ttk::radiobutton .r1 -text R1 -value R1 -variable ::ns::someVar
.r1
% ttk::radiobutton .r2 -text R2 -value R2 -variable ::ns::someVar
.r2
% pack .r1 .r2 -side top
% puts $::ns::someVar
% # clicks upon r1
% puts $::ns::someVar
R1
% # clicks upon r2
% puts $::ns::someVar
R2
%
The thing is, they do have to be 'fully qualified' (which is something
that is easy to forget).
In Tcl 8 a syntax like
-var ::ns::someVar
is not illegal: it just doesn't have any effect
As I show above, it does. But, for a radio button, you do need to give
each widget a -value or the widget never sets anything into the
variable.
Hello,
many thanks to both of you for responding. I am sorry to not having
reacted sooner but I was pretty sick (thank you Covid :( ).
@Rich: Your demo was quite convincing. Still, I'm sure that whenever I
tried it in the past it always failed - too late to find out why and
not really important.
@ Harald: Too much honor - my question was what Rich assumed. To tell
the truth: It took me quite a while to even understand what you
assumed I had meant - I am much simpler minded :)
Have a nice weekend
Helmut
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 119:23:36 |
Calls: | 12,958 |
Files: | 186,574 |
Messages: | 3,265,634 |