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!

basic tk gui help

Status
Not open for further replies.

tansac

Technical User
Apr 18, 2013
2
US
Hi,

I am a newbee and wanted to learn tk widget. currently i have couples fruit items that associated with checkbuttons. i want to print out all fruit selected when click on "Run" button.

my codes below are not completed but Please help!

##############################################
proc frame_with_check_button { filelist loc } {
set left_frame [frame $loc.left_frame -bg black]
set filenames [label $left_frame.filenamesframe -bg black -fg darkorange -borderwidth 4 -anchor n -text " Fruit Selection " -font "arial 12 bold"]
pack $filenames
foreach name $filelist {
set but [ checkbutton $left_frame.$name -text $name -bg darkorange -anchor w ]
bind $but <1> { puts "click on [%W cget -text]"}
pack $but -fill x
}
return $left_frame
}
set testList {apple orange pear grape grapefruit banana watermelon mango pipeapple}
set topframe [frame .top -bg blue]
set topframeLabel [label .top.l -bg snow -fg red -anchor n -text "* TK GUI *" -font "arial 16 bold"]
set listbut [frame_with_check_button $testList $topframe]
set run [button .top.r -text " Run " -bg coral4 -fg darkorange -font "arial 18 bold" -command {puts "selected: "}]
set closeb [button .top.c -text "** Close **" -bg coral3 -fg darkorange -font "arial 18 bold" -command {destroy $topframe}]
pack $topframe $topframeLabel $listbut $run $closeb $listbut





 
Please use code tags (the <> icon) and tell us what it's doing or not doing that you want to change.

_________________
Bob Rashkin
 
##############################################
proc frame_with_check_button { filelist loc } {
set left_frame [frame $loc.left_frame -bg black]
set filenames [label $left_frame.filenamesframe -bg black -fg darkorange -borderwidth 4 -anchor n -text " Fruit Selection " -font "arial 12 bold"]
pack $filenames
foreach name $filelist {
set but [ checkbutton $left_frame.$name -text $name -bg darkorange -anchor w ]
bind $but <1> { puts "click on [%W cget -text]"}
pack $but -fill x
}
return $left_frame
}
##############################################
set testList {apple orange pear grape grapefruit banana watermelon mango pipeapple}
set topframe [frame .top -bg blue]
set topframeLabel [label .top.l -bg snow -fg red -anchor n -text "* TK GUI *" -font "arial 16 bold"]
set listbut [frame_with_check_button $testList $topframe]
set run [button .top.r -text " Run " -bg coral4 -fg darkorange -font "arial 18 bold" -command {puts "selected: < print out \ all checked button>"}]
set closeb [button .top.c -text "** Close **" -bg coral3 -fg darkorange -font "arial 18 bold" -command {destroy $topframe}]
pack $topframe $topframeLabel $listbut $run $closeb $listbut

At the Run button, using -command to print out all checked buttons, ex: ---> selected apple grape pipeable






 
Hi,
Had some spare time, been a while visiting this forum, here my 2 cents for what it's worth:

Additional script to main part:
Code:
set ::sel ""
$run config -command {puts "selected: $sel"}
proc add2List {selected add} {if {$add} {set ::sel "$::sel$selected "} {set ::sel [regsub -all $selected $::sel ""]}}

Inside proc frame_with_check_button, do the following change:
Code:
set but [checkbutton $left_frame.$name -text $name -bg darkorange -anchor w -variable $name -command "eval {add2List $name \$$name}"]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top