The code below creates a listbox which grabs names from a seperate file called build.txt Ive created the list box and the button but I am having trouble binding the button to the elements in the listbox. How do I set it up so that when I press the button it outputs the highlighted item in the listbox??
Here is the code:
wm title . "Automated Builds"
. config -bg grey50
label .label1 -text "Select which kit to build:"
pack .label1
proc Scroll_Set {scrollbar geoCmd offset size} {
if {$offset != 0.0 || $size != 1.0} {
eval $geoCmd;
$scrollbar set $offset $size
} else {
set manager [lindex $geoCmd 0]
$manager forget $scrollbar;
}
}
proc Scrolled_Listbox {f args} {
frame $f
listbox $f.list -xscrollcommand [list Scroll_Set $f.xscroll [list grid $f.xscroll -row 1 -column 0 -sticky we]] -yscrollcommand [list Scroll_Set $f.yscroll [list grid $f.yscroll -row 0 -column 1 -sticky ns]]
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal -command [list $f.list xview]
scrollbar $f.yscroll -orient vertical -command [list $f.list yview]
grid $f.list $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
proc List_Select { parent values } {
frame $parent
set choices [Scrolled_Listbox $parent.choices -width 20 -height 5]
pack $parent.choices -side left -expand true -fill both
foreach x $values {
$choices insert end $x
}
}
set t [Scrolled_Listbox .f -width 40 -height 8]
pack .f -side top -fill both -expand true
set in [open "/tcl scripts/build.txt"]
while {[gets $in line] >= 0 } {
$t insert end $line
}
close $in
button .one -text "build"
pack .one -side right
Scrolled_Listbox
Here is the code:
wm title . "Automated Builds"
. config -bg grey50
label .label1 -text "Select which kit to build:"
pack .label1
proc Scroll_Set {scrollbar geoCmd offset size} {
if {$offset != 0.0 || $size != 1.0} {
eval $geoCmd;
$scrollbar set $offset $size
} else {
set manager [lindex $geoCmd 0]
$manager forget $scrollbar;
}
}
proc Scrolled_Listbox {f args} {
frame $f
listbox $f.list -xscrollcommand [list Scroll_Set $f.xscroll [list grid $f.xscroll -row 1 -column 0 -sticky we]] -yscrollcommand [list Scroll_Set $f.yscroll [list grid $f.yscroll -row 0 -column 1 -sticky ns]]
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal -command [list $f.list xview]
scrollbar $f.yscroll -orient vertical -command [list $f.list yview]
grid $f.list $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
proc List_Select { parent values } {
frame $parent
set choices [Scrolled_Listbox $parent.choices -width 20 -height 5]
pack $parent.choices -side left -expand true -fill both
foreach x $values {
$choices insert end $x
}
}
set t [Scrolled_Listbox .f -width 40 -height 8]
pack .f -side top -fill both -expand true
set in [open "/tcl scripts/build.txt"]
while {[gets $in line] >= 0 } {
$t insert end $line
}
close $in
button .one -text "build"
pack .one -side right
Scrolled_Listbox