Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a list with checkboxes

Status
Not open for further replies.

FreddieBlassie

Programmer
Dec 11, 2001
20
US
I have a group of checkboxes that have independent onValues associated to them. I am trying to find a way to create a list using these checkboxes, so that when a checkbox is selected its onValue is added to this list (named portList) and when it is deselected it is removed. I'm not sure if I would have to call a procedure to accomplish this or what. Could someone help me with it? Thanks...Here's the part I can figure out:

checkbutton .check1 -text 1 -onvalue {1 1 1}
checkbutton .check2 -text 2 -onvalue {1 1 2}
checkbutton .check3 -text 3 -onvalue {1 1 3}
checkbutton .check4 -text 4 -onvalue {1 1 4}
 
Try that:
---------------------------
set ::var1 0; set ::var2 0; set ::var3 0; set ::var4 0
set ::list {}
pack [checkbutton .check1 -text 1 -variable ::var1 ]
pack [checkbutton .check2 -text 2 -variable ::var2 ]
pack [checkbutton .check3 -text 3 -variable ::var3 ]
pack [checkbutton .check4 -text 4 -variable ::var4 ]
pack [label .label -textvariable ::list]
trace variable ::var1 w varying
trace variable ::var2 w varying
trace variable ::var3 w varying
trace variable ::var4 w varying
proc varying {args} {
set ::list {}
foreach v {::var1 ::var2 ::var3 ::var4} { eval "if {$$v} { lappend ::list $v }" }
}
---------------------------

The trace commands associate the varying proc to a change in a checkbutton.
The varying proc constructs the string for the label with all the variable names of the checked buttons.

The ::var syntax indicates that the ::variables are global (needed by -variable & -textvariable options).

ulis
 
OK thanks Ulis...I actually ended up doing it another way before I read your reply. The program is designed to submit a series of onvalues when a button is clicked, and instead of making the GUI interact with the checkboxes before the button is clicked, I just put a series of if statements in the button-click proc pertaining to whether the checkboxes were selected or not. I guess that way is a little bit simpler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top