Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

radiobuttons enable/disable textboxes

43 views
Skip to first unread message

mluc

unread,
Apr 14, 2017, 8:48:15 PM4/14/17
to
Hi all,
I need a little help in this please.
I have 2 radio buttons, but only one of them, when selected, there is a textbox for entry a number.
i.e
radiobutton .radA -variable select -value A -text "A" -width 5
radiobutton .radB -variable select -value B -text "B" -width 5

I have a textbox:
entry .txt -textvariable val -state disable -width 8

once user select radB, the idea is to enable the textbox so user can enter data.
by default radA is selected.

I'm using the following to change the textbox status, but nothing happens

if {[".radB" select]==true} {
entry .txt -textvariable val -state normal -width 8 }

any suggestions?
thanks


Rich

unread,
Apr 14, 2017, 9:42:40 PM4/14/17
to
Please show a complete example of your code, not just random snippets.

Based upon your snippets, you are not executing your "status change"
code when the radio buttons are clicked. In which case you should look
into the "-command" option for the radio button.

Olivier

unread,
Apr 15, 2017, 6:02:30 PM4/15/17
to
And look into the subcommand "configure" associated with an entry widget, instead of redefining a .txt widget ... It is also a bad idea to name a variable "select" which is the name of a command.

mluc

unread,
Apr 15, 2017, 7:43:06 PM4/15/17
to
thanks all. I'll posted when it will be working.

Donald Arseneau

unread,
Apr 21, 2017, 9:20:57 PM4/21/17
to
That doesn't make any sense, but maybe the context of where
you are using those lines would change my opinion.

You say you want to react to the USER selecting .radB, but here
you force selection yourself with [".radB" select], so it seems
you understand it backwards. What you want instead is to perform
the action using the -command option on the radiobuttons. You
probably should NOT create and destroy the entry box repeatedly,
but enable and disable it:

entry .txt -textvariable val -state normal -width 8
radiobutton .radA -variable select -value A -text "A" -width 5 -command txtena
radiobutton .radB -variable select -value B -text "B" -width 5 -command txtena

proc txtena { } {
.txt configure -state [expr { $::select eq "B" ? "normal" : "disabled" }]
}


--
Donald Arseneau as...@triumf.ca
0 new messages