INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

basic tk gui help

basic tk gui help

(OP)
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





RE: basic tk gui help

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

_________________
Bob Rashkin

RE: basic tk gui help

(OP)
##############################################
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






RE: basic tk gui help

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}"] 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close