Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

guess the number

By: a guest on Feb 10th, 2012  |  syntax: TCL  |  size: 1.01 KB  |  hits: 130  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package require Tk
  2.  
  3. namespace eval guess {
  4.     variable max 100
  5.     variable min 1
  6.     variable count -1
  7.     variable guess 0
  8.     namespace export *
  9. }
  10.  
  11. proc guess::gui {} {
  12.     pack [label .g]
  13.     pack [frame .c] -pady 5
  14.     pack [button .c.l -text "Lower" -command guess::lower] -side left -padx 3
  15.     pack [button .c.h -text "Higher" -command guess::higher] -side left -padx 3
  16.     pack [button .c.ok -text "Done" -command guess::done] -side left -padx 3
  17.     guess::next
  18. }
  19.  
  20. proc guess::next {} {
  21.     variable min
  22.     variable max
  23.     variable guess
  24.     variable count
  25.     incr count
  26.     set guess [expr {($max+$min)/2}]
  27.     .g conf -text "The number is: $guess ?"
  28. }
  29.  
  30. proc guess::higher {} {
  31.     variable guess
  32.     variable min $guess
  33.     guess::next
  34. }
  35.  
  36. proc guess::lower {} {
  37.     variable guess
  38.     variable max $guess
  39.     guess::next
  40. }
  41.  
  42. proc guess::done {} {
  43.     variable count
  44.     .g conf -text "Guessed it in $count tries."
  45.     .c.ok conf -text Exit -command exit
  46. }
  47.  
  48. guess::gui