<OT> tcl/tk question: Radio buttons
Roger Oberholtzer
roger
Mon May 17 11:57:12 PDT 2004
A checkbutton wants a boolean variable. You have assigned a string to a
variable, resulting in a non-boolean being attached to the radio button.
I seem to always use checkbutton with the variable statement. A radiobutton
is a boolean thing, so the variable indicating it's state should be boolean
in nature.
If you want a command to be called when the variable changes state (either
because the radio button was used) or because you set it to the desired
boolean directly, use the trace command:
trace add variable cb w {my script}
Then, whenever 'cb' is written to, {my script} is executed. This is a very
powerful feature of Tcl.
On Sun, 21 Dec 2003 20:12:49 -0500
Joel Hammer <joel at hammershome.com> wrote:
> I just want to get this point cleared up before I go off in the wrong
> direction.
>
> I have found if I change the global variable (-variable) associated with
> a checkbutton, the button stops responding.
>
> I have included a program snippet below, as I think you can't have
> attachments on this list.
>
> Basically, when I click a radio button, and run a command like
>
> -command {puts "string"}
>
> all works as expected. However, if I change the radiobutton option
> -variable in the command, with something like:
>
> -command {set cb "You ran a program"}
Be aware that 'cb' in this context will by default be a global variable. If
you want to access it in a proc, add this to the beginning of the proc:
global cb
>
> the radio button stops responding. cb is my -variable in this radiobutton.
>
> It makes no difference if I remove the -onvalue and -offvalue options.
>
> Is this a bug or a feature or am I missing something?
>
> Thanks,
>
> Joel
>
>
> #!/etc/alternatives/wish -f
> frame .myframe2
> pack .myframe2 -anchor w
>
> # The command in the next line is the problem
> checkbutton .myframe2.cb -text "Choice 2" -onvalue True -offvalue False
> -variable cb -command {set cb "You ran a program"}
>
> # This next line works fine
> # checkbutton .myframe2.cb -text "Choice 2" -onvalue True -offvalue False
> -variable cb -command {puts "You changed me"}
#2 works because you did not change 'cb' into a string variable by assigning
it a "string" value, as you did in #1.
> label .myframe2.lcb -textvariable cb
> pack .myframe2.cb .myframe2.lcb -side left
>
> _______________________________________________
> Linux-users mailing list
> Linux-users at smtp.linux-sxs.org
> Unsubscribe/Suspend/Etc ->
> http://smtp.linux-sxs.org/mailman/listinfo/linux-users
>
--
+????????????????????????????+???????????????????????????????+
? Roger Oberholtzer ? E-mail: roger at opq.se ?
? OPQ Systems AB ? WWW: http://www.opq.se/ ?
? Erik Dahlbergsgatan 41-43 ? Phone: Int + 46 8 314223 ?
? 115 34 Stockholm ? Mobile: Int + 46 733 621657 ?
? Sweden ? Fax: Int + 46 8 302602 ?
+????????????????????????????+???????????????????????????????+
More information about the Linux-users
mailing list